loop over section of array javascript code example

Example 1: javascript iterate array

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

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

Example 2: javascript loop through array

var colors = ["red","blue","green"];
colors.forEach(function(color) {
  console.log(color);
});

Example 3: how to loop through array of numbers in javascript

let numbers = [1,2,3,4,5];
let numbersLength = numbers.length;
for ( let i = 0; i < numbersLength; i++) {
    console.log (numbers[i]);
}