I'm trying to do this PHP equivalent in javascript.
How can I do the same loop I did with PHP in javascript?
I'm trying to do this PHP equivalent in javascript.
How can I do the same loop I did with PHP in javascript?
You got the basic syntax of looping wrong:
for (json.messages in object){
alert(object.message);
}
Assuming that you want to loop the messages in json.messages, and using a name other than object as that might be a system built-in, you would actually write it as follows:
for (alertMessage in json.messages){
alert(alertMessage);
}
See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration
you got basically the position of variable and array wrong: variable comes left side of the in.