freeCodeCamp Challenge Guide: Manipulate Arrays With pop

freeCodeCamp Challenge Guide: Manipulate Arrays With pop
0

#1

Another way to change the data in an array is with the .pop() function.

.pop() is used to “pop” a value off of the end of an array. We can retrieve this value by performing pop() in a variable declaration.

Any type of variable can be “popped” off of an array.

Right answer is:
var myArray = [[“John”, 23], [“cat”, 2]];
var removedFromMyArray = myArray.pop()


#2

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


#3

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();