alltolove 发表于 2017-7-16 06:31:44

es6语法之Map()对象

小贴士:小心闪电


static/image/hrline/line9.png


map是个hash数据结构,查询速度会相当快,而且他与set不同的是可以存储相同的数据
let json={
        name:'alltolove',
        age:37
}
let map=new Map()
map.set('me',json)
document.write(map.get('me').name)
他的键和值可以存储任何类型数据,网页显示为:



let json={
        name:'alltolove',
        age:37
}
let map=new Map()
map.set('me',json)
map.set(12,)
map.forEach((k,v)=>document.write(v))
也可以遍历,网页显示为:



let json={
        name:'alltolove',
        age:37
}
let map=new Map()
map.set('me',json)
map.set(12,)
map.delete(12)
map.forEach((k,v)=>document.write(v))
也可以删除一条数据,网页显示:




let json={
        name:'alltolove',
        age:37
}
let map=new Map()
map.set('me',json)
map.set(12,)

document.write(map.has(12))
也可以用has方法查询,网页上显示:



let json={
        name:'alltolove',
        age:37
}
let map=new Map()
map.set('me',json)
map.set(12,)

document.write(map.size)
可以查询一共几条数据,显示为:



页: [1]
查看完整版本: es6语法之Map()对象