xxxxxxxxxx
var fruits = ["Orange", "Apple", "Mango"];
var moreFruits = ["Banana", "Lemon", "Kiwi"];
fruits.push(moreFruits);
//fruits => ["Orange", "Apple", "Mango", "Banana", "Lemon", "Kiwi"]
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
// 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
var arrayA = [1, 2];
var arrayB = [3, 4];
var newArray = arrayA.concat(arrayB);
xxxxxxxxxx
// To merge two or more arrays you shuld use concat() method.
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]