Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop

Tell us what’s happening:
I think the last task of the page might confuse people where it says:

removedFromMyArray should only contain ["cat", 2] .

But that array is what we’re supposed to remove and this array should stay:
[“John”, 23]

Please correct me if I am wrong.

Your code so far


// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line
var removedFromMyArray = myArray.pop();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.

Challenge: Manipulate Arrays With pop()

Link to the challenge:

1 Like

pop() removes the last item from an array and stores it in a variable. So the initial array, if called after the pop() action will exclude the removed item.

You are not wrong :slight_smile:

1 Like

.pop() removes the last element from an array and returns that element.

Look at the name of the variables:

myArray should only contain [["John", 23]] .

removedFromMyArray should only contain ["cat", 2] .

they are correct. myArray starts as [["John", 23], ["cat", 2]], you remove the last element with pop, and then it remains as [["John", 23]]
meanwhile the removed element is stored in removedFromMyArray

1 Like