a iterable collection of key-value entries, unique keys
constmap=newMap();let len =map.length; //0map.set('a',0);map.set('b',1);map.has('a'); // true/* return a new iterator object contain all elements in insertion order*/let iter =map.entries();iter.next().value // ['a',0]/* return a new iterator object contain the keys */let keys =map.keys();keys.next().value; // 'a'/* return a new iterator object contain the values */let vals =map.values();vals.next().value; // 0map.delete('a') // true, successfully remove element, ow return falsemap.forEach((k,v) => v +=1);map.get('b'); //2map.has('c'); // falsemap.clear(); // remove all pairs from the map object
Object
Pairs of names(strings) and values(any value)
constobj=newObject();constobj2= {a:1, b:2};/* copy the value of all enumerate properties to target object */Object.assign(obj, obj2); // {a: 1, b: 2}; return obj/* creates a new object, using an existing object as the prototype */constobj3=Object.create(obj);constarr=Object.entries(obj); //[[a,1],[b,2]]constkeys=Object.keys(obj); //['a','b']constvals=Object.values(obj); //[1,2]Object.freeze(obj); //freeze an object, cannot be changed after. constobj4=Object.fromEntries([['k','c'],['l',5']]); // {k:'c', l:5}Object.is(obj, obj1); //falseObject.is('bar','bar'); //trueObject.isExtensible(obj); //true, determines if an object is extensibleObject.isFronzen(obj); //true, determines if an object is frozen
Set
Store unique values of any type
constset1=newSet();set1.add(42); //[42]set1.add(13); //[42,13]set1.delete(42); //[13]set1.forEach(v => {if (v >20) set1.delete(v); } set1.has(10); //falseconst iter =set1.entries();const vals =set1.values(); const keys =set1.keys(); //same as values() in map