iteration of str in array js code example
Example 1: javascript loop through array
var colors = ["red","blue","green"];
colors.forEach(function(color) {
console.log(color);
});
Example 2: 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
}