首页 > 编程知识 正文

js遍历map的几种方式,JS遍历map集合以及map对象

时间:2023-05-05 17:59:02 阅读:240168 作者:3246


  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

转载于:https://www.cnblogs.com/wuqilang/p/11204656.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。