add array in array javascript code example
Example 1: javascript append to array
var colors=["red","white"];
colors.push("blue");
Example 2: javascript append array to array
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
Example 3: insert into array js
var list = ["hello", "world"];
list.splice( 1, 0, "bye");
["hello", "bye", "world"]
Example 4: javascript adding an array to an array
let chocholates = ['Mars', 'BarOne', 'Tex'];
let chips = ['Doritos', 'Lays', 'Simba'];
let sweets = ['JellyTots'];
let snacks = [];
snacks.concat(chocholates);
snacks.concat(chocolates, chips, sweets);
Example 5: add item to array javascript
const arr1 = [1,2,3]
const newValue = 4
const newData = [...arr1, obj]
Example 6: how to make and add to an array in javascript
var arrayExample = [53,'Hello World!'];
console.log(arrayExample)
[53,'Hello World!']
arrayExample.push(true);
console.log(arrayExample);
[53,'Hello World!',true];