node js array push code example

Example 1: js array add element

array.push(element)

Example 2: js push array

array.push(element_to_push);

Example 3: js push array

var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]

Example 4: js array push

const arr = ["foo", "bar"];
arr.push('baz'); // 3
arr; // ["foo", "bar", "baz"]

Example 5: 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']

Example 6: javascript array push

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

fruits.push("Banana");