freeCodeCamp Challenge Guide: Manipulate Arrays With pop()

Manipulate Arrays With pop()


Problem Explanation

Remove the last element in the array and assign it to removedFromMyArray.


Hints

Hint 1

Call .pop() on the array, and assign it to removedFromMyArray.


Solutions

Solution 1 (Click to Show/Hide)
// Setup
var myArray = [["John", 23], ["cat", 2]];

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

the instructions were
Use the .pop() function to remove the last item from myArray, assigning the “popped off” value to removedFromMyArray.

my code was
var ourArray = [1,2,3];
var removedFromOurArray = ourArray.pop();
// removedFromOurArray now equals 3, and ourArray now equals [1,2]

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

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

but it asks me to use pop() on myArray… anyhow the last element is already removed

5 Likes

This worked for me

var ourArray = [1,2,3];
var removedFromOurArray = ourArray.pop();
// removedFromOurArray now equals 3, and ourArray now equals [1,2]

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

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

9 Likes