FAQ: Arrays - The .pop() Method

This community-built FAQ covers the “The .pop() Method” exercise from the lesson “Arrays”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise The .pop() Method

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

4 posts were split to a new topic: Example for using the .pop() method code that is not used in lesson?

5 posts were split to a new topic: Why the last item gets removed since we only “saved it” in a variable

4 posts were split to a new topic: Still don’t get it how

2 posts were split to a new topic: If i double pop an array shouldn’t it be returned with all the elements except the last 2?

2 posts were split to a new topic: Does the value still exist even if we remove it from our array?

2 posts were split to a new topic: What does it mean to mutate?

3 posts were split to a new topic: Can we remove more values using .pop() operator?

The problem with this exercise is that it does not explicitly specify that chores.pop(); deletes the item, while const removed = chores.pop(); stores it. I had the same problem and I had to experiment for some time with the code to figure it out.

2 Likes

just a little notice, the link for the MDN array documentation is broken, it can’t be “clicked”. you can copy the url and paste it in a new window tho.

for this lesson: https://www.codecademy.com/courses/introduction-to-javascript/lessons/arrays/exercises/pop

P.S. The link in the project: “Secret Message” at the end of the array module is broken in the same way.

2 posts were split to a new topic: Does pop() need parameters?

2 posts were split to a new topic: They didn’t call .pop on the array

2 posts were split to a new topic: Why you do this in dedicated copy, not original array itself?

4 posts were split to a new topic: Make us do code that has no bearing on the lesson

3 posts were split to a new topic: Can I remove more than one item at a time using .pop()?

12 posts were split to a new topic: Why does the list get printed first as a list

2 posts were split to a new topic: .push() - don’t get the same array, get a number

I’m kind of confused or maybe its a bug, i don’t know, the .pop() method is supposed to remove the last item of an array, but in this example, the item before the last one was removed (i.e ‘cook dinner’), I console log it to see the item removed, it was the second to the last word ‘cook dinner’ and calling the array again, it removed the last two item [‘cook dinner’, ‘mop floor’]. i’m confuse here.
here is the code:
const chores = [‘wash dishes’, ‘do laundry’, ‘take out trash’, ‘cook dinner’, ‘mop floor’];

chores.pop();

console.log(chores.pop())

console.log(chores);

you call .pop() twice? So two items are removes, but the first time you are not logging the removed item

so that means, this code; console.log(chores.pop()) is not logging the removed item but also removing another item and logging it to the console. Thank you, I understand better now.