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 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM