tagArray = new Array('a','b','c');
$.each(tagArray, function(index, value) {
i开发者_C百科f(typeof value == 'undefined')
return false;
console.log(index + " " + value);
});
Given the above code, I get the following response: 0 a 1 b 2 c undefined
Why is $.each() going one index too far, also, why is my conditional failing this check?
That code works fine, and if it was really going one index too far it would output (note the 3):
0 a
1 b
2 c
3 undefined
not
0 a
1 b
2 c
undefined
Here is a JSFiddle to prove to you that it works: http://jsfiddle.net/Paulpro/AhdMn/
You must be logging something later in your code that is undefined.
精彩评论