Created
October 20, 2014 05:02
-
-
Save lizlongnc/90f5d7a263aca2adfffd to your computer and use it in GitHub Desktop.
JS .push() & .pop()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function range(max) { | |
var retVal = []; | |
for (var i = 0; i < max; i++) { | |
retVal.push(i * 2); | |
} | |
return retVal; | |
} | |
var myArray = range(5); | |
for (var i = 0; i < myArray.length; i++) { | |
alert(myArray[i]); | |
} | |
var myArrayPop = myArray.pop(); // .pop() returns last value in an array and also removes it from the array | |
alert(myArrayPop); | |
alert(myArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment