Answers for "get index from array using for loop javascript"

5

js for of array with index

for (const [index, value] of [1, 2, 3, 4, 5].entries()) {
  console.log(index, value);
}
Posted by: Guest on June-18-2021
0

use index of an array within a for loop

const logArrayElements = (element, index, array) => {
  console.log('a[' + index + '] = ' + element);
};

// Notice that index 2 is skipped, since there is no item at
// that position in the array...
[2, 5,, 9].forEach(logArrayElements);
// logs:
// a[0] = 2
// a[1] = 5
// a[3] = 9
Posted by: Guest on February-10-2022

Code answers related to "get index from array using for loop javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language