Skip to content

Instantly share code, notes, and snippets.

@danawoodman
Created March 11, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danawoodman/d485279d19990ad839433dc40c14fb65 to your computer and use it in GitHub Desktop.
Save danawoodman/d485279d19990ad839433dc40c14fb65 to your computer and use it in GitHub Desktop.
Javascript array examples
// Lots of examples here:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
const arr = [ 1, 2, 3 ]
// first item in array:
arr[0]
// last item:
arr[2]
// Number of items in array:
arr.length // => 3
// Add item to end of array:
arr.push(4) // => [ 1, 2, 3, 4]
// Add item to start of array
arr.unshift(0) // => [ 0, 1, 2, 3, 4 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment