1
2let chocholates = ['Mars', 'BarOne', 'Tex'];
3let chips = ['Doritos', 'Lays', 'Simba'];
4let sweets = ['JellyTots'];
5
6let snacks = [];
7snacks.concat(chocholates);
8// snacks will now be ['Mars', 'BarOne', 'Tex']
9// Similarly if we left the snacks array empty and used the following
10snacks.concat(chocolates, chips, sweets);
11//This would return the snacks array with all other arrays combined together
12// ['Mars', 'BarOne', 'Tex', 'Doritos', 'Lays', 'Simba', 'JellyTots']
13
1const myArray = ['hello', 'world'];
2
3// add an element to the end of the array
4myArray.push('foo'); // ['hello', 'world', 'foo']
5
6// add an element to the front of the array
7myArray.unshift('bar'); // ['bar', 'hello', 'world', 'foo']
8
9// add an element at an index of your choice
10// the first value is the index you want to add at
11// the second value is how many you want to delete (0 in this case)
12// the third value is the value you want to insert
13myArray.splice(2, 0, 'there'); // ['bar', 'hello', 'there', 'world', 'foo']