Arrays are datastructures. Unlike objects, they use indices.
- Declare an array like so:
const arrayName = ['array-value', 'array-value2', 'array-value3']
-
arrayName.lengthHow many items are in an array -
arrayName[1]Access content from a known index position
- Add element to the end of the array:
arrayName.push('content') - Add element to the beginning of the array
arrayName.unshift('content')
NOTE: These can be used to assign the value from an array to a variable
- Remove an element from the end of the array.
arrayName.pop() - Remove an item from the start of the array
arrayName.shift()
const arrayName3 = arrayName1.concat(arrayName2)Merge two or more arrays togetherarrayName.splice(start-number, delete-number, 'content')Remove or replace existing elements or add new elements at the index of the start-number. if the delete number is set to 0, it will just input the new content at whatever index point you specify with the start number
arrayName.indexOf('item-name');This will give you the index position of an array item. works well with splice for when you want to find where something is to replace it.