1 let {keys, values, entries} = Object 2 let a = { 3 "b":'1', 4 "c":'2', 5 "d":'3' 6 } 7 for (let s of keys(a)) { 8 // b c d 9 console.log(s) 10 } 11 for (let s of values(a)) { 12 // 1 2 3 13 console.log(s) 14 } 15 for (let s of entries(a)) { 16 // ["b":'1'],["c":'2'],["d":'3'] 17 console.log(s) 18 }
注:上面是使用for...of来进行遍历,下面的是常用的
1 for (let s in a) { 2 // b c d 3 console.log(s) 4 // 1 2 3 5 console.log(a[s]) 6 }