Answers for "how to iterate for all elements of array in js"

48

javascript loop thrugh array

var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}
Posted by: Guest on July-22-2019
1

iterate through array javascript

for (var key in validation_messages) {
    // skip loop if the property is from prototype
    if (!validation_messages.hasOwnProperty(key)) continue;

    var obj = validation_messages[key];
    for (var prop in obj) {
        // skip loop if the property is from prototype
        if (!obj.hasOwnProperty(prop)) continue;

        // your code
        alert(prop + " = " + obj[prop]);
    }
}
Posted by: Guest on July-16-2020

Code answers related to "how to iterate for all elements of array in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language