J.Lee
0
Q:

js add array items to array

 // SPREAD OPERATOR
 const list1 = ["pepe", "luis", "rua"];
 const list2 = ["rojo", "verde", "azul"];
 const newList = [...list1, ...list2];
 // ["pepe", "luis", "rua", "rojo", "verde", "azul"]
2

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']
6
a1.splice(2, 0, ...a2);
0
//adding items to array
objects = [];
objects.push("you can add a string,number,boolean,etc");
//if you more stuff in a array
//before i made a error doing value = : value
objects.push({variable1 : value, variable2 : value);
//we do the {} so we tell it it will have more stuff and the variable : value
0
var arrayA = [1, 2];
var arrayB = [3, 4];
var newArray = arrayA.concat(arrayB);
-2

New to Communities?

Join the community