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 store this "popped off" value by assigning it to a variable.
Any type of entry can be "popped" off of an array - numbers, strings, even nested arrays.
For example, for the codevar oneDown = [1, 4, 6].pop();
the variable oneDown
now holds the value 6
and the array becomes [1, 4]
.
Use the .pop()
function to remove the last item from myArray
, assigning the "popped off" value to removedFromMyArray
.