what does the following mean?
$.each(json.results, function(i, item) {
...
}
I kind of understand the other parts of the line, but if you could explain that as well, I’d appreciate it.
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.
$.eachprovides a simple iterator and it will execute the callback function once for each element in the array.For my examples, lets assume:
In addition to using the parameters (
index, item), thethisvariable in each callback can be used to reference the current item.UPDATE: This example changed to show use of the other parameters:
The first parameter is the index of the current item in the loop. It is a zero based index. The second parameter is the item of the current iteration. You can use
thisor the variable, but the variable comes in handy in situations like this:Additionally, there are a few controls you can use similar to the
breakandcontinuestatements.If you want to
continueornextat any point, usereturn true;If you want to
break, usereturn false;