how to .push javascript code example

Example 1: push array javascript

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"]

Example 2: add value to array javascript

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

fruits.push("Kiwi");

Example 3: javascript add item to list

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

Example 4: javascript array push

// 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']

Tags:

Java Example