insert element in array javascript code example
Example 1: javascript insert item into array
var colors=["red","blue"];
var index=1;
colors.splice(index, 0, "white");
Example 2: add item to list javascript
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: javascript array add
let yourArray = [1, 2, 3];
yourArray.push(4);
Example 5: add array to array javascript
const list1 = ["pepe", "luis", "rua"];
const list2 = ["rojo", "verde", "azul"];
const newList = [...list1, ...list2];
Example 6: javascript Inserting values in between an array
myArray.splice(index, itemsToDelete, item1ToAdd, item2ToAdd, ...)