// Suppose we have an array
let myArray = [2, 4, 6, 8, 10];
// Index where we want to insert the item
let indexToInsert = 3;
// ItemThe item we want to insert
let itemToInsert = 174;
// Now we Usingare using the splice() method to insert the item at the specified index
myArray.splice(indexToInsert, 0, itemToInsert);
// outputOutput with the new value
console.log(myArray);
Active reading [<https://en.wiktionary.org/wiki/use#Verb> <https://www.youtube.com/watch?v=1Dax90QyXgI&t=17m54s>].
Peter Mortensen
- reputation score 30948
- 22 gold badges
- 111 silver badges
- 134 bronze badges
lang-js