xxxxxxxxxx
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"]
xxxxxxxxxx
var array = [];
var element = "anything you want in the array";
array.push(element); // array = [ "anything you want in the array" ]
xxxxxxxxxx
var vegetables = ['Capsicum',' Carrot','Cucumber','Onion'];
vegetables.push('Okra');
//expected output ['Capsicum',' Carrot','Cucumber','Onion','Okra'];
// .push adds a thing at the last of an array
xxxxxxxxxx
//the array comes here
var numbers = [1, 2, 3, 4];
//here you add another number
numbers.push(5);
//or if you want to do it with words
var words = ["one", "two", "three", "four"];
//then you add a word
words.push("five")
//thanks for reading
xxxxxxxxxx
An example of Array.push
let arr = ['abc', 'def'];
console.log(arr); // -> [ 'abc', 'def' ]
arr.push('ghi');
console.log(arr); // -> [ 'abc', 'def', 'ghi' ]
xxxxxxxxxx
const arr = ["foo", "bar"];
arr.push('baz'); // 3
arr; // ["foo", "bar", "baz"]
xxxxxxxxxx
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"]
xxxxxxxxxx
const array1 = [1,2];
const array2 = [3,4];
const array3 = array1.concat(array2);