Map和object区别
1.Map是有序结构
2.map操作同样很快
3.Map可以以任意类型为key, 两者api也不同
代码演示
const m = new Map([
['key1', 'monster'],
['key2', 'hunter'],
['key3', {x: 'rise'}]
])
m.set('key4', 'sunbreak')//新增
m.has('key1')//判断是否有key1
m.delete('key1')//删除
m.forEach((value, key) => {console.log(value, key)})//遍历
m.size //map长度
//Map可以任意类型为key
const p = {name: 'xx'}
m.set(p, 'test')
console.log(m)