JS遍历map结构

 1 let map = new Map()
 2 map.set('first','hellow')
 3 map.set('second','world')
 4 console.log(map) //Map(2) {"first" => "hellow", "second" => "world"}
 5 for (let s of map.keys()) {
 6     console.log(s)//first second
 7 }
 8 for (let s of map.values()) {
 9     console.log(s)//hello world
10 }
11 for (let s of map.entries()) {
12     console.log(s) //["first", "hellow"] ["second", "world"]
13 }
1 for (let [key, value] of map) {
2     console.log(key, value) //"first", "hellow" 和 "second", "world"
3 }
posted @ 2020-08-10 15:11  yw3692582  阅读(1445)  评论(0)    收藏  举报