js array insert code example
Example 1: javascript insert item into array
var colors=["red","blue"];
var index=1;
colors.splice(index, 0, "white");
Example 2: js add item to array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Example 3: insert into array js
var list = ["hello", "world"];
list.splice( 1, 0, "bye");
["hello", "bye", "world"]
Example 4: add element to array using splice
const strings=['a','b','c','d']
strings.splice(2,0,'alien')
console.log(strings)
Example 5: js push array
array.push(element_to_push);
Example 6: add array to array javascript
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [...list1, ...list2];