Iterating thru an array using javascript for

How do I iterate thru an array like this using ‘for’ in jquery. This one has me totally lost. I cant figure how to get those values out from an array like this

 //Php
    $errors['success']   = false;
    $errors['#errOne']   = "Enter a valid username";
    $errors['#errTwo']   = "Enter a valid email";
    $errors['#errThree'] = "Enter a valid password";
    echo json_encode($errors);//
dataType:"json",
    cache:false,
    success: function(data){
    for (i=1; i<?; i++){//Start at 1
    //I'm totally lost here.
    //#errOne "Enter a valid username" ->Loop thru remaining messages
    }
	},

You would check that the index is less than data.length as the loop condition, and start from 0 as that’s the first item in an array.

However, that is just with numeric arrays. You have non-numeric keys being used, so you will need to loop through the objects of that array instead.


var key;
for (key in data) {
    if (data.hasOwnProperty(key)) {
        // use data[key] here
    }
}

Thanks, Paul. This is just what I was looking for. Can’t believe I couldn’t figure this out myself :slight_smile: Thanks for helping.