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
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15755848.html
未经授权禁止转载,违者必究!