javascript prevent loop through string instead of array code example
Example 1: javascript code to loop through array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: javascript loop through array
const myArray = ["foo","bar"];
// New version
myArray.map(item => console.log(item));
//or
myArray.forEach(item => console.log(x));
//Older version
for(let i = 0; i < myArray.length; i++) {
console.log(myArray[i]);
}