1//adding items to array
2objects = [];
3objects.push("you can add a string,number,boolean,etc");
4//if you more stuff in a array
5//before i made a error doing value = : value
6objects.push({variable1 : value, variable2 : value);
7//we do the {} so we tell it it will have more stuff and the variable : value
8
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']
1let fruit = ['apple', 'banana']
2fruit.push('cherry')
3console.log(fruit) // ['apple', 'banana', 'chery']