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?
The only explanation for this is the that items array contains values which are undefined, i.e :
Both of the other answers are wholly incorrect. The first parameter of
eachis the index, not the value, and jQuery.fn.each calls jQuery.each. There is no disambiguation between them.