xxxxxxxxxx
const sports = ['Football', 'Tennis']
sports.push('Basketball') // => ['Football', 'Tennis', 'Basketball']
xxxxxxxxxx
const arr = [1, 2, 3, 4];
arr.push(5);
console.log(arr); // [1, 2, 3, 4, 5]
// another way
let arr = [1, 2, 3, 4];
arr = [arr, 5];
console.log(arr); // [1, 2, 3, 4, 5]
xxxxxxxxxx
// SPREAD OPERATOR
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [list1, list2];
// ["pepe", "luis", "rua", "rojo", "verde", "azul"]
xxxxxxxxxx
const langages = ['Javascript', 'Ruby', 'Python'];
langages.push('Go'); // => ['Javascript', 'Ruby', 'Python', 'Go']
const dart = 'Dart';
langages = [langages, dart]; // => ['Javascript', 'Ruby', 'Python', 'Go', 'Dart']
xxxxxxxxxx
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
xxxxxxxxxx
const myArray = ['hello', 'world'];
// add an element to the end of the array
myArray.push('foo'); // ['hello', 'world', 'foo']
// add an element to the front of the array
myArray.unshift('bar'); // ['bar', 'hello', 'world', 'foo']
// add an element at an index of your choice
// the first value is the index you want to add at
// the second value is how many you want to delete (0 in this case)
// the third value is the value you want to insert
myArray.splice(2, 0, 'there'); // ['bar', 'hello', 'there', 'world', 'foo']