How to use for-of loop with index and value in JavaScript ES6

1 Answer

0 votes
const arr = [23, 76, 181, 89, 9187, 12];

for (const [index, element] of arr.entries()) {
    console.log(index + '. ' + element);
}

     
/*
run:
   
0. 23
1. 76
2. 181
3. 89
4. 9187
5. 12
 
*/

 



answered Mar 8, 2020 by avibootz

Related questions

1 answer 171 views
2 answers 185 views
1 answer 168 views
2 answers 246 views
1 answer 142 views
...