Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,423 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
210,423 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
210,423 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