node foreach index code example

Example 1: typescript foreach

let num = [7, 8, 9];
num.forEach(function (value) {
  console.log(value);
});

Example 2: javascript foreach index

users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});

Example 3: foreach jas

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));

Example 4: js for each item do

let array = ['Item 1', 'Item 2', 'Item 3'];

array.forEach(item => {
	console.log(item); // Logs each 'Item #'
});

Example 5: javascript enumerate with index

const iterable = [...];
for (const [index, elem] in iterable.entries()) {
  f(index, elem);
}

// or
iterable.forEach((elem, index) => {
  f(index, elem);
});

Example 6: forEach index

const array1 = ['a', 'b', 'c'];

array1.forEach((element, index) => console.log(element, index));

Tags:

Java Example