JSON array :
var json_array = [
{ "A" : "1" },
{ "B" : "2" }
];
How can I make a JS function that acts on every element of the array? Like..
$.each(json_array, function() { ...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Two suggestions.
JSON is just text. You have an actual JavaScript array,
once you remove the outer curly braces from your code.Don’t use JQuery for this. The plain old JavaScript
forEachalready works on regular arrays, which is, what I think, you want.ADDENDUM
Using JavaScript’s
forEach:If you have an old browser (IE <= 8), replace the
forEachcall with (suggestion due to Asad):JQuery’s
eachis for jQuery objects.