Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAurelio Decock
14,607 PointsQuestion about task
In a task we needed to create a var for shifting in the array and popping in the array. The array had 3 numbers or strings in it (can't actually remember it anymore).
First we had to shift the first one, then pop the last. I used the code below.
var shifting = orderQueue.shift(0);
var pop = orderQueue.pop(2):
I completed the task though but it seems more logical to me to pop(1) instead of 2 since the array only contained 2 pieces of data?
1 Answer
daviem
21,118 PointsHi Aurelio,
The pop() method doesn't need you to pass a number as an argument to tell it the position of the last element(in fact it ignores it when you do) because it always pops off the last element of the array automatically anyways This is confusing because you've been thinking about which number to pass in to remove the last element, when in fact it doesn't need it.
In short, if you want to remove the last element of an array, just doing orderQueue.pop() will suffice.
Hope this helps,
good luck bud.
Aurelio Decock
14,607 PointsAurelio Decock
14,607 PointsOk I got it, thanks alot! :)