Reassigning an array with a popped of item as a new variable

Tell us what’s happening:
Hi
How do I go about using the poop function to take an item of the end of a list and declare a new variable with the altered array?

I thought maybe, cosole.log(newArray.pop(3)) for example but it just prints the value being taken off>

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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Edg/88.0.705.56.

Challenge: Manipulate Arrays With pop()

Link to the challenge:

myArray is already updated after pop. You don’t need to reassign.

It’s ok to reassign the popped off value to removedFromMyArray, that’s what the challenge is asking you to do (and by the way, your code passes for me, so it’s correct).

.pop() doesn’t take a parameter, you don’t have to specify what you want to pop off the array, .pop() just removes the last item in the array, and - important - it returns the value that was popped off.

You can either just modify the array with myArray.pop(), or you can additionally store the removed item in a variable:

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

myArray.pop(); // .pop() changes the array:

console.log(myArray) // [["John", 23]]

var anotherRemovedItem = myArray.pop() // changes the array again, and it's now empty:

console.log(myArray) // []
console.log(anotherRemovedItem) // ["John", 23]

Now,
myArray = [[“John”, 23]];
removedFromMyArray = [[“cat”, 2]];

myArray is the altered array you are looking for.