append array in array javascript code example

Example 1: javascript append to array

var colors=["red","white"];
colors.push("blue");//append 'blue' to colors

Example 2: javascript append element to array

var colors= ["red","blue"];
	colors.push("yellow");

Example 3: javscript append item from array

let foo = ['oop','plop','copo'];
	foo.push("plop");

Example 4: javascript append element to array

// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

// append new value to the array
arr.push("Hola");

console.log(arr);

Example 5: how to append an element to an array in javascript

//Use push() method
//Syntax: 
array_name.push(element);
//Example: 
let fruits = ["Mango", "Apple"];
//We want to append "Orange" to the array so we will use push() method
fruits.push("Orange"); 
//There we go, we have successfully appended "Orange" to fruits array!

Example 6: javascript append to array

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

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