how to add an item to an array code example

Example 1: javascript append to array

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

Example 2: js array add element

array.push(element)

Example 3: javascript pushing to an array

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

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

Example 4: php add element to array

<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
?>

Example 5: javscript append item from array

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

Example 6: append an array

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

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

console.log(arr);