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

用JavaScript遍历Map数据类型的方法

最编程 2024-01-14 21:38:41
...


  1、forEach遍历:

map.forEach(function(value,key){
console.log(value,key);
});
 函数中第一个参数是属性值,第二个参数是属性

2、for-of遍历:
①for(let item of map){

 }
 遍历结果是数组
②for(let item of map.values()){

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

 }
 遍历属性

3、entries遍历:

for(let item of map.entries()){

}
 遍历结果同forEach

推荐阅读