开发者

why does array.shift skip a value?

开发者 https://www.devze.com 2022-12-19 11:21 出处:网络
I have this function $(this).each(function(index) { arr[index] = ($(this).attr(\'id\')); console.log(arr[index]);

I have this function

$(this).each(function(index) {

            arr[index] = ($(this).attr('id'));
            console.log(arr[index]);            

            fullId[index] = "开发者_如何学JAVA#"+arr.shift();
            console.log(fullId[index]);     
});

The results I'm expecting are

A
#A
B
#B
C
#C
D
#D

The actual results are

A
#A
B
Undefined
C
#B
D
Undefined

Why is this?


You realize that shifting arr changes the indexes of all items in the array, right?

And yet won't affect $(this) at all?

0

精彩评论

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

关注公众号