Answers for "js each array"

56

javascript foreach

var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});
Posted by: Guest on June-27-2019
11

javascript foreach index

users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});
Posted by: Guest on June-19-2020
2

array.foreach

const arr = [0, 3, "hola", "hello", ";", true, [3, 6, 1]];
arr.forEach((element, index) => {
    console.log(element, index);
});

//output:

// 0 0
// 3 1
// hola 2
// hello 3
// ; 4
// true 5
// [3, 6, 1] 6
Posted by: Guest on April-06-2021
1

js for each item in array

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

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

// expected output: "a"
// expected output: "b"
// expected output: "c"
Posted by: Guest on January-15-2021
6

foreach loop javascript

const numList = [1, 2, 3];

numList.forEach((number) => {
  console.log(number);
});
Posted by: Guest on October-05-2020
1

for each array javascript

var fruits = ["apple", "orange", "cherry"];
fruits.forEach(getArrayValues);

function getArrayValues(item, index) {
  console.log( index + ":" + item);
}
/*
result:
0:apple
1:orange
2:cherry
*/
Posted by: Guest on December-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language