// ES6 Set
let instruments = new Set();
// or ไธ้ๅงๅฐฑๆๅผๅญ้ฒๅป
let instruments = new Set(['1','2']);
instruments.add('piano');
instruments.has('guitar'); // false
instruments.delete('guitar'); // ่ฃก้ขๆ นๆฌๆฒๆ guitar ๆไปฅๅๅณ false
instruments.size; // 1
[...instruments] //['piano']
// or use Array.from,
Array.from(instruments);
let myMap= new Map();
// or ไธ้ๅงๅฐฑๅญๅผ๏ผ่จๅพๆฏ [[]] double array
let myMap = new Map([[keyString ,'value']]);
var keyString = 'I am string',
keyObj = {},
keyFunc = function() {},
keyNumber = 1
// ๅขๅ
myMap.set(keyString , 'string value');
myMap.set(keyObj, {obj: 1});
myMap.set(keyFunc , function(){console.log('I am function')});
myMap.set(keyNumber , 100);
// ๆๅนพๅ
myMap.size; // 4
// ๅๅผ
myMap.get(keyObj); // {obj: 1}
// ็ๆฏๅฆๅญๅจ
myMap.has(keyString ); // true
// ๅชๆ
myMap.delete(keyNumber);
myMap.size; // 3
// ่ฝ้ฃๅ
[...myMap.values()] // ["string value", {obj: 1}, ฦ]
if( lookup.has(str) ){
lookup.set(str, lookup.get(str) + 1 )
} else {
lookup.set(str, 1 )
}
lookup.set(str, (lookup.get(str) ?? 0) + 1 )
if( !lookup.has(sortStr) ){
lookup.set(sortStr, [str] )
} else {
lookup.set(sortStr, [...lookup.get(sortStr), str] )
}
// ๅฏไปฅ่ฎไปฅไธ
lookup.set(sortStr, [...(lookup.get(sortStr) ?? []), str] )