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-2026 CODEPRJ.COM