0
Q:

how to push an element into an array in javascript

var colors=["red","white"];
colors.push("blue");//append 'blue' to colors
79
array.push(element)
27
var colors= ["red","blue"];
	colors.push("yellow"); 
41
let items = [1, 2, 3]
items.push(4); // items = [1, 2, 3, 4]
6
var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.push("Kiwi"); 
0
// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

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

console.log(arr);
3

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

fruits.push("Kiwi"); 
0

New to Communities?

Join the community