JS中for..of对象的遍历补充

 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 }

 

posted @ 2020-08-10 17:03  yw3692582  阅读(1844)  评论(0)    收藏  举报