Created
March 11, 2019 20:24
-
-
Save danawoodman/d485279d19990ad839433dc40c14fb65 to your computer and use it in GitHub Desktop.
Javascript array examples
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
// 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