JS iterator进行遍历Map Set

 1    'use strict'
 2         //遍历数组元素
 3         var arr = [3,4,5]
 4         for (var arrKey of arr) {
 5             console.log(arrKey)
 6         }
 7         //遍历map
 8         var map = new Map([["张三",20],["李四",28],["王五",35]])
 9         for (let x of map) {
10             console.log(x)
11         }
12         //遍历set
13         var set = new Set([5,6,7])
14         for (let x of set) {
15             console.log(x)

运行结果:

posted @ 2021-02-14 20:53  贩卖人烟  阅读(278)  评论(0编辑  收藏  举报