js iterating over array code example
Example 1: js loop through array
// ES6 for-of statement
for (const color of colors){
console.log(color);
}
// Array.prototype.forEach
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});
// Sequential for loop
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
//Do something
}
Example 2: how to iterate array in javascript
array = [ 1, 2, 3, 4, 5, 6 ];
//set variable//set the stop count // increment each loop
for (let i = 0; i < array.length ;i++) {
array[i] //iterate through each index.
//add the intructions you would like to perform.
// add any method to array[
}