开发者

jQuery $.each() goes one index too far

开发者 https://www.devze.com 2023-03-31 01:01 出处:网络
tagArray = new Array(\'a\',\'b\',\'c\'); $.each(tagArray, function(index, value) { i开发者_C百科f(typeof value == \'undefined\')
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号