Get loop counter/index using for…of syntax in JavaScript

后端 未结 11 1976
走了就别回头了
走了就别回头了 2020-11-28 00:55

Caution:

question still applies to for…of loops.> Don\'t use for…in to iterate over an Array, use it

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 01:12

    Answer Given by rushUp Is correct but this will be more convenient

    for (let [index, val] of array.entries() || []) {
       // your code goes here    
    }
    

提交回复
热议问题