欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

玩转JS Map!三种遍历方式大揭秘

最编程 2024-01-14 21:32:56
...

1、forEach遍历:

map.forEach((key,val)=>{
    ...//操作
}

key是属性值,val是属性

2、for of遍历:

for(let item of map){
    ...
}
//遍历键值对数组

for(let item of map.values()){
    ...
}
//遍历属性值
for(let item of map.keys()){
    ...
}
//遍历属性

3、entries遍历:

for(let [key,val] of map.entries()){
    ...
}
//类似forEach遍历