how to push array into array in javascript code example

Example 1: javascript pushing to an array

some_array = ["John", "Sally"];
some_array.push("Mike");

console.log(some_array); //output will be =>
["John", "Sally", "Mike"]

Example 2: add array to array javascript

// SPREAD OPERATOR
 const list1 = ["pepe", "luis", "rua"];
 const list2 = ["rojo", "verde", "azul"];
 const newList = [...list1, ...list2];
 // ["pepe", "luis", "rua", "rojo", "verde", "azul"]

Example 3: javascript array push

var fruits = [ "Orange", "Apple", "Mango"];

fruits.push("Banana");

Example 4: javascript append to array

arr = [1, 2, 3, 4]
arr.push(5) // adds element to end

arr.unshift(0) // adds element to beginning

Example 5: js push

let arr = [9, 4, 3, 18]
arr.push(30)
console.log(arr) // [9, 4, 3, 18, 30]

Example 6: push javascript

/*The push() method adds elements to the end of an array, and unshift() adds
elements to the beginning.*/
let twentyThree = 'XXIII';
let romanNumerals = ['XXI', 'XXII'];

romanNumerals.push(twentyThree);
// now equals ['XIX', 'XX', 'XXI', 'XXII', 'XXIII']

romanNumerals.unshift('XIX', 'XX');
// now equals ['XIX', 'XX', 'XXI', 'XXII']

Tags:

Java Example