Section 1 - Instruction

Last time, we learned how to add items to the end of an array using .push(), which lets our arrays grow.

Engagement Message

But what if we need to take an item out of an array? For example, removing the last task you added.

Section 2 - Instruction

JavaScript arrays have a simple method that is the perfect opposite of .push(): the .pop() method.

This method removes the item from the very end of the array. The array gets shorter by one item.

Engagement Message

Does .pop() seem like a useful tool for an "undo" feature?

Section 3 - Instruction

The syntax is simple: arrayName.pop();. It doesn't need any arguments inside the parentheses because it always knows to remove the last item.

Engagement Message

If we have ["milk", "eggs", "bread"]; and try using pop(), how many elements do you think will remain?

Section 4 - Instruction

After shopping.pop();, the array becomes ["milk", "eggs"]. The last item, "bread", is gone.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal