push items in array javascript code example

Example 1: js add item to array

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

Example 2: add value to array javascript

var fruits = ["222", "vvvv", "eee", "eeee"];

fruits.push("Kiwi");

Example 3: javascript array push

var fruits = [ "Orange", "Apple", "Mango"];

fruits.push("Banana");

Example 4: array.push

var vegetables = ['Capsicum',' Carrot','Cucumber','Onion'];
vegetables.push('Okra');
//expected output ['Capsicum',' Carrot','Cucumber','Onion','Okra']; 
// .push adds a thing at the last of an array

Example 5: add item to array javascript

const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj] // [1,2,3,4]

Example 6: javascript array push

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

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

console.log(arr);

Tags:

Misc Example