add item to end of array javascript code example

Example 1: javascript append element to array

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

Example 2: javascript pushing to an array

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

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

Example 3: js add item to array

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

Example 4: javascript array add end

// example:
let yourArray = [1, 2, 3];
yourArray.push(4); // yourArray = [1, 2, 3, 4]

// syntax:
// <array-name>.push(<value-to-add>);

Example 5: js push array

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

Example 6: javascript add items to array

//adding items to array
objects = [];
objects.push("you can add a string,number,boolean,etc");
//if you more stuff in a array
//before i made a error doing value = : value
objects.push({variable1 : value, variable2 : value);
//we do the {} so we tell it it will have more stuff and the variable : value