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 }

 

相关文章:

  • 2022-02-12
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2022-01-25
相关资源
相似解决方案