CREATION
new Date(year, month, date, hours, minutes, seconds, ms)
new Date(year, month, date)
let now = new Date();
ACCESSING DATE COMPONENTES
getFullYear() getMonth() getDate() getHours(),
- getMinutes(), getSeconds(), getMilliseconds() getDay()
- getUTCFullYear() getUTCMonth(), getUTCDay(). getTime()
- getTimezoneOffset()
- CALCULATING DATE DIFFERENCE
- alert("The loop took ${end -start} ms"
/ we have date1 and date2, which function faster returns their difference in ms? function diffSubtract(date1, date2) { return date2 - date1; } // or function diffGetTime(date1, date2) { return
date2.getTime() - date1.getTime(); }
- PARSING DATE
- let ms = Date.parse(''2013-02-21");
- Keep updating ....
- -
- -
- MAPS :
- Map is a collection of keyed data items, just like an
Object
. But the main difference is thatMap
allows keys of any type.The main methods are:new Map()
– creates the map.map.set(key, value)
– stores the value by the key.map.get(key)
– returns the value by the key,undefined
ifkey
doesn’t exist in map.map.has(key)
– returnstrue
if thekey
exists,false
otherwise.map.delete(key)
– removes the value by the key.map.clear()
– clears the mapmap.size
– returns the current element count.
ITERATION map.keys()
– returns an iterable for keys,map.values()
– returns an iterable for values,map.entries()
– returns an iterable for entries[key, value]
, it’s used by default infor..of
.
- SET
- Its main methods are:
new Set(iterable)
– creates the set, optionally from an array of values (any iterable will do).set.add(value)
– adds a value, returns the set itself.set.delete(value)
– removes the value, returnstrue
ifvalue
existed at the moment of the call, otherwisefalse
.set.has(value)
– returnstrue
if the value exists in the set, otherwisefalse
.set.clear()
– removes everything from the set.set.size
– is the elements count.
// a number in JSON is just a number alert( JSON.stringify(1) ) // 1 // a string in JSON is still a string, but double-quoted alert( JSON.stringify('test') ) // "test" alert( JSON.stringify(true) ); // true alert( JSON.stringify([1, 2, 3]) ); // [1,2,3]
Namely:- Function properties (methods).
- Symbolic properties.
- Properties that store
undefined
.
let user = { sayHi() { // ignored alert("Hello"); }, [Symbol("id")]: 123, // ignored something: undefined // ignored }; alert( JSON.stringify(user) ); // {} (empty object)
let json = JSON.stringify(value[, replacer, space])
- -
- -
No comments:
Post a Comment