how to iterate an array js code example

Example 1: iterate through array javascript

const array = ["one", "two", "three"]
array.forEach(function (item, index) {
  console.log(item, index);
});

Example 2: javascript iterate array

var txt = "";
var numbers = [45, 4, 9, 16, 25];

numbers.forEach(function(value, index, array) {
  txt = txt + value + "<br>";
});

Example 3: javascript loop through array

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

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

Example 4: iterate over array javascript

var txt = "";
var numbers = [45, 4, 9, 16, 25];
numbers.forEach(myFunction);

function myFunction(value, index, array) {
  txt = txt + value + "<br>";
}

Tags:

Java Example