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 trialDaniel Haasenritter
Courses Plus Student 3,463 PointsConfusing Question
Not sure what they are asking here. Push adds to the end, Pop removes an item from the end. Shift and Unshift do the same to the front. None do both. Am I reading the question incorrectly?
"Which array method returns the first item from an array and removes it from the array?"
2 Answers
andren
28,558 PointsWhich array method returns the first item from an array and removes it from the array?
By return, they mean that the method returns the value back to the code that called it. Not that any value is added to the array, and the answer to this question is shift
. Both shift
and pop
return the value that they remove.
As an example take this code:
var scores = [ 76, 79, 85, 87, 89 , 90, 99];
var firstScore = scores.shift();
console.log(firstScore);
76 will be printed if you run that code. That comes from the fact that scores.shift()
returns the value it removed from the array, which means that you can assign it to a variable as I have done above. If shift
did not return what it removed then the above would not work.
Daniel Haasenritter
Courses Plus Student 3,463 PointsOkay, It's a Syntax thing. I was confused on the verbage. Thank you.
andren
28,558 Pointsandren
28,558 PointsCan you specify what exact question confuses you? There are multiple in the Quiz and it's not entirely clear which you are referring to. It would help if you edited your post with the question.