xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js Map All In One

js Map All In One

const map = new Map();
map.set(0, 1);
map.set(1, 1);
map.set(2, 3);
map.set(3, 4);

console.log('size =', map.size);

for([key, value] of map) {
   console.log('key, value', key, value);
}

Object vs Map

const map = new Map([[1, 1], ['b', 'b'], [3, '3c']]);
for (const [key, value] of map) {
  console.log('key, value =', key, value);
}

const obj = {
  1: 1,
  b: 'b',
  3: '3c',
};
for (const [key, value] of Object.entries(obj)) {
  console.log('key, value =', key, value);
}

const arr = [1, 'b', '3c']
for (const [index, value] of Object.entries(arr)) {
  console.log('index, value =', index, value);
}

ES6 Map All In One

https://www.cnblogs.com/xgqfrms/p/13995530.html

refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#cloning_and_merging_maps



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-01-01 18:48  xgqfrms  阅读(39)  评论(1编辑  收藏  举报