pop()
always removes the last element of an array. What if you want to remove the first?
That's where .shift()
comes in. It works just like .pop()
, except it removes the first element instead of the last.
.shift()
function to remove the first item from myArray
, assigning the "shifted off" value to removedFromMyArray
.
myArray
should now equal [["dog", 3]]
.
testString: assert((function(d){if(d[0][0] == 'dog' && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray));
- text: removedFromMyArray
should contain ["John", 23]
.
testString: assert((function(d){if(d[0] == 'John' && d[1] === 23 && typeof removedFromMyArray === 'object'){return true;}else{return false;}})(removedFromMyArray));
```