xxxxxxxxxx
const vegetables = ['parsnip', 'potato'];
const moreVegs = ['celery', 'beetroot'];
// Merge the second array into the first one
vegetables.push(moreVegs);
console.log(vegetables); // ['parsnip', 'potato', 'celery', 'beetroot']
xxxxxxxxxx
let array = ["A", "B"];
let variable = "what you want to add";
//Add the variable to the end of the array
array.push(variable);
//===========================
console.log(array);
//output =>
//["A", "B", "what you want to add"]
xxxxxxxxxx
// SPREAD OPERATOR
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [list1, list2];
// ["pepe", "luis", "rua", "rojo", "verde", "azul"]
xxxxxxxxxx
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
xxxxxxxxxx
var fruits = ["Orange", "Apple", "Mango"];
var moreFruits = ["Banana", "Lemon", "Kiwi"];
fruits.push(moreFruits);
//fruits => ["Orange", "Apple", "Mango", "Banana", "Lemon", "Kiwi"]
xxxxxxxxxx
const array1 = [1,2];
const array2 = [3,4];
const array3 = array1.concat(array2);
xxxxxxxxxx
var arrayA = [1, 2];
var arrayB = [3, 4];
var newArray = arrayA.concat(arrayB);