views:

62

answers:

1

I have this function

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

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

            fullId[index] = "#"+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?

+3  A: 

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

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

Anon.
I don't understand your answer/question?
Catfish
Try printing the entirety of `arr` after each call to `shift`. It'll make the problem clear.
Anon.
Ohh ok i see what's going on. Thanks man.
Catfish