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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Removing Items From Arrays

seong lee
seong lee
4,503 Points

cant 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
Steven Parker
231,236 Points

I 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
Steven Parker
231,236 Points

The "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
seong lee
4,503 Points

Thank 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
Steven Parker
231,236 Points

I 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
seong lee
4,503 Points

Thank you Steven Parker, I love how you help every single person you see

seong lee
seong lee
4,503 Points

Wait steven I still need you to explain why you cant us the pop method to get rid of the 2