Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  94] [ 7]  / answers: 1 / hits: 24460  / 14 Years ago, sun, july 25, 2010, 12:00:00

I have the following code



function myFunction(items) {
// this prints out 11
alert(items.length);

$(items).each(function(i, item) {
// item is undefined for some reason
}
}


It I alert the length of items, it has elements in it (11 to be exact). so how could 11 items be present, but jQuery still pass undefined?


More From » jquery

 Answers
2

The only explanation for this is the that items array contains values which are undefined, i.e :



items = [undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined];


Both of the other answers are wholly incorrect. The first parameter of each is the index, not the value, and jQuery.fn.each calls jQuery.each. There is no disambiguation between them.


[#96115] Thursday, July 22, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;