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 }

浙公网安备 33010602011771号