1users.forEach((user, index)=>{
2 console.log(index); // Prints the index at which the loop is currently at
3});
1const iterable = [...];
2for (const [index, elem] in iterable.entries()) {
3 f(index, elem);
4}
5
6// or
7iterable.forEach((elem, index) => {
8 f(index, elem);
9});
1var myArray = [123, 15, 187, 32];
2
3myArray.forEach(function (value, i) {
4 console.log('%d: %s', i, value);
5});
6
7// Outputs:
8// 0: 123
9// 1: 15
10// 2: 187
11// 3: 32
12