0
Q:

push item to array js

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

fruits.push("Kiwi"); 
0
let array = ["A", "B"];
let variable = "what you want to add";

//Add the variable to the end of the array
array.push(variable);

//===========================
console.log(array);
//output =>
//["A", "B", "what you want to add"]
12
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
11
// JS array .push() method

let items_in_backpack = ['food', 'water', 'flashlight', 'GPS']; // Our starting array
items_in_backpack.push('javascript array push knowledge'); // Adds the <<< string to the array items_in_backpack


// Now the array is:
// ['food', 'water', 'flashlight', 'GPS', 'javascript array push knowledge']

2

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

fruits.push("Kiwi"); 

console.log(fruits) // ["Banana", "Orange", "Apple", "Mango", "Kiwi"]
3
const arr = ["foo", "bar"];
arr.push('baz'); // 3
arr; // ["foo", "bar", "baz"]
6
var fruits = [ "Orange", "Apple", "Mango"];

fruits.push("Banana"); 
4
let animals = ["dog","cat","tiger"];

animals.pop(); // ["dog","cat"]

animals.push("elephant"); // ["dog","cat","elephant"]
3
var SomeRandomArray = [];
SomeRandomArray.push("Hello, world!");
8

New to Communities?

Join the community