0
Q:

javascpirt push in aray

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
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
const animals = ['pigs', 'goats', 'sheep'];

const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]

animals.push('chickens', 'cats', 'dogs');
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]
2

New to Communities?

Join the community