push element in array code example

Example 1: javascript append element to array

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

Example 2: add item to list javascript

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

Example 3: pushing to an array

array = ["hello"]
array.push("world");

console.log(array);
//output =>
["hello", "world"]

Example 4: js push array

var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]

Example 5: how to push items in array in javascript

let items = [1, 2, 3]
items.push(4); // items = [1, 2, 3, 4]

Tags:

Ruby Example