Skip to content

Instantly share code, notes, and snippets.

@lizlongnc
Created October 20, 2014 05:02
Show Gist options
  • Save lizlongnc/90f5d7a263aca2adfffd to your computer and use it in GitHub Desktop.
Save lizlongnc/90f5d7a263aca2adfffd to your computer and use it in GitHub Desktop.
JS .push() & .pop()
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