Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Created January 30, 2012 23:34
Show Gist options
  • Save karlwestin/1707528 to your computer and use it in GitHub Desktop.
Save karlwestin/1707528 to your computer and use it in GitHub Desktop.
Shift, unshift, push, pop in javascript
var arr = [1,2,3,4,5,6,7];
var first = arr.shift(); // first = 1, arr = [2,3,4,5,6,7]
arr.unshift(0); // arr = [0,2,3,4,5,6,7]
arr.push(8); // arr = [0,2,3,4,5,6,7,8]
var last = arr.pop() // last = 8, arr = [0,2,3,4,5,6,7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment