js array add element
snippet in javascript

js array add element

user4074

array.push(element)

javascpirt push in aray

user8195


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

fruits.push("Kiwi"); 

console.log(fruits) // ["Banana", "Orange", "Apple", "Mango", "Kiwi"]

javascript append element to array

user3771

// initialize array
var arr = [
  "Hi",
  "Hello",
  "Bonjour"
];

// append new value to the array
arr.push("Hola");

console.log(arr);

javascript adding an array to an array

user6377


let chocholates = ['Mars', 'BarOne', 'Tex'];
let chips = ['Doritos', 'Lays', 'Simba'];
let sweets = ['JellyTots'];

let snacks = [];
snacks.concat(chocholates);
// snacks will now be ['Mars', 'BarOne', 'Tex']
// Similarly if we left the snacks array empty and used the following
snacks.concat(chocolates, chips, sweets);
//This would return the snacks array with all other arrays combined together
// ['Mars', 'BarOne', 'Tex', 'Doritos', 'Lays', 'Simba', 'JellyTots']

javascript array push method

user5084


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

fruits.push("Kiwi");

push javascript

user6434

let fruit = ['apple', 'banana']
fruit.push('cherry')
console.log(fruit) // ['apple', 'banana', 'chery']