javascript how to iterate through an array with a for loo code example
Example 1: js loop through array
for (const color of colors){
console.log(color);
}
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
}
Example 2: iterate through array javascript
for (var key in validation_messages) {
if (!validation_messages.hasOwnProperty(key)) continue;
var obj = validation_messages[key];
for (var prop in obj) {
if (!obj.hasOwnProperty(prop)) continue;
alert(prop + " = " + obj[prop]);
}
}