0

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?

1 Answer 1

4

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand your answer/question?
Try printing the entirety of arr after each call to shift. It'll make the problem clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.