pablocattaneo
2/18/2018 - 8:44 PM

How to get the index in a for...of loop

How to get the index in a for...of loop #index #Typescript #Javascript

https://stackoverflow.com/questions/36108110/typescript-for-of-with-index-key

for (const {item, index} of someArray.map((item, index) => ({ item, index }))) {
    console.log(item); // 9, 2, 5
    console.log(index); // 0, 1, 2
}