add new item in array javascript code example

Example 1: add item to list javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi"); // Fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];

Example 2: push array javascript

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"]

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