Learn

We’re also able to remove items from a list.

Similar to adding items, we can modify lists by taking off the last item, or we can use indexing to select a specific item and remove it from the list. Removing from the end of a list is often referred to as pop or popping.

Imagine a list of the numbers 1, 4, and 10. Popping from this list would remove 10, leaving 1 and 4.

But we can also remove items from the middle of our list. Removing from index 1 of the list 4, 7, 3 would remove 7. This would leave 4 and 3.

Instructions

For this exercise we will be using new removeAtIndex and pop as well as add at index. Use these to make the list on the left match the list on the right.

Hint
We need to add Blue, remove red and one of the pinks.
Solution
Remove at index 0 Add blue at index 1 Pop

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?