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 trialseong lee
4,503 Pointscant you just do this: var number = [1,2,3,4,5,6] number.pop(2)
Cant you just pop out a number like that without having to use the shift method
4 Answers
Steven Parker
231,236 PointsI thought I said that the first time. The "pop" method doesn't take an argument and always removes the last item.
But you could get rid of the 2 using "splice":
number.splice(1, 1);
Steven Parker
231,236 PointsThe "pop" method doesn't take an argument (it will ignore any given).
While "shift" removes the first item from an array, "pop" removes the last item from the array.
seong lee
4,503 PointsThank you but I have one more question. In this quiz what is the answer to the question that asks to store the numbers like 78, 81, 83, and few other numbers : https://teamtreehouse.com/library/javascript-arrays-and-loops/tracking-multiple-items-with-arrays/review-adding-and-removing-items-from-arrays
Steven Parker
231,236 PointsI believe the question you are referring to is asking for the number of items. The number of items in an array can be access by using the length property.
seong lee
4,503 PointsThank you Steven Parker, I love how you help every single person you see
seong lee
4,503 PointsWait steven I still need you to explain why you cant us the pop method to get rid of the 2