iterate over list javascript code example

Example 1: iterate through list javascript

const array = ["hello", "world"];

for (item of array) {
	//DO THIS
}

Example 2: iterate array in javascrpt

let array = [ 1, 2, 3, 4 ]; //Your array

for( let element of array ) {
	//Now element takes the value of each of the elements of the array
	//Do your stuff, for example...
  	console.log(element);
}

Example 3: 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>";
}

Example 4: iterate through array javascript

foreach ($objects as $obj) {
   echo $obj->property;
}

Tags:

Java Example