Arrays Defintion
Arrays are list-like objects whose prototype has methods to perform traversal and mutation (the action or process of changing) operations. The length of a JavaScript array nor the types of its elements are fixed.
An array is a special type of variable, which can store multiple values. Each value is associated with numeric index starting with 0.
Create an array
// these are the two ways to create an empty array
let emotions = new Array();
let emotions = [];
// we add items to the array
let emotions = ['๐', '๐']
console.log(emotions.length)
//2
Access an Array item by using its index position
let first = emotions[0]
// '๐'
let last = emotions[emotions.length - 1]
// '๐'
Loop over the array
emotions.forEach(function(item, index, array) {
console.log(item, index)
})
// '๐' 0
// '๐' 1
Add an item to the end of an Array
let newLength = emotions.push('๐ฅฐ')
// ['๐', '๐', '๐ฅฐ']
Remove an item from the end of an Array
let last = emotions.pop() // remove ๐ฅฐ (from the end)
// ['๐', '๐']
Remove an item from the beginning of an Array
let first = emotions.shift() // remove ๐ from the front
// ['๐']
Find the index of an item in the Array
emotions.push('๐ฅณ')
// ['๐', '๐', '๐ฅณ']
let pos = emotions.indexOf('๐')
// 1
Learn more about Arrays
here ๐๐พ