Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
1 of 4
Shashintha Janadari

// Suppose we have an array
let myArray = [2, 4, 6, 8, 10];

// Index where we want to insert the item
let indexToInsert = 3;

// Item we want to insert
let itemToInsert = 174;

// Now we Using splice() method to insert the item at the specified index
myArray.splice(indexToInsert, 0, itemToInsert);

// output with new value
console.log(myArray);

Shashintha Janadari