You want the splice function on the native array object.

arr.splice(index, 0, item); will insert item into arr at the specified index (deleting 0 items first, that is, it's just an insert).

In this example we will create an array and add an element to it into index 2:

var arr = [];
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";
arr[3] = "Kai Jim";
arr[4] = "Borge";

console.log(arr.join()); // Jani,Hege,Stale,Kai Jim,Borge
arr.splice(2, 0, "Lene");
console.log(arr.join()); // Jani,Hege,Lene,Stale,Kai Jim,Borge

UPDATE (24 May 2024)

You can now use the toSpliced method which behaves just like splice, however it returns a new array without mutating the existing one.

You could update the previous example like so:

const updated = arr.toSpliced(2, 0, "Lene");
Answer from tvanfosson on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org › news › insert-into-javascript-array-at-specific-index
How to Insert into a JavaScript Array at a Specific Index – JS Push
November 7, 2024 - In this code, the splice() method is called on the numbers array, starting at index 2, with a deleteCount of 0. You then add the new element 3 to the array at the start index. The result is the modified array [1, 2, 3, 4, 5]. In this article, you have learned the two major techniques for inserting elements into a JavaScript array at a specific index.
🌐
DigitalOcean
digitalocean.com › community › questions › how-to-insert-an-item-into-an-array-at-a-specific-index-with-javascript
How to insert an item into an array at a specific index with JavaScript? | DigitalOcean
April 9, 2023 - In this example, we inserted the ‘grape’ element at index 1 in the fruits array. The splice() method offers a simple and efficient way to insert an item into an array at a specific index in JavaScript.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-insert-an-item-into-an-array-at-a-specific-index-in-javascript.php
How to Insert an Item into an Array at a Specific Index in JavaScript
You can use the splice() method to insert a value or an item into an array at a specific index in JavaScript. This is a very powerful and versatile method for performing array manipulations.
🌐
Stack Abuse
stackabuse.com › javascript-how-to-insert-elements-into-a-specific-index-of-an-array
JavaScript: How to Insert Elements into a Specific Index of an Array
September 25, 2023 - To add an element to the end of an array, we can use the fact that the length of an array is always one less than the index. Say, the length of an array is 5, then the last index at which the value will be 4. So, we can directly add the element at the last+1 index.
🌐
Sentry
sentry.io › sentry answers › javascript › how to insert an item into an array at a specific index using javascript
How to insert an item into an array at a specific index using JavaScript | Sentry
The first argument of the splice() ... The second argument is the deleteCount. To add elements to an array, add each element as an additional argument....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-inserting-multiple-items-at-specific-index-in-js-array
JavaScript - Inserting Multiple Items at Specific Index in JS Array ...
July 11, 2025 - ... let a = [10, 20, 30, 40, 50]; const i = 2; const a1 = [99, 100, 101]; a = [...a.slice(0, i), ...a1, ...a.slice(i)]; console.log(a); ... JS Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.
🌐
Programiz
programiz.com › javascript › examples › insert-item-array
JavaScript Program to Insert Item in an Array
// program to insert an item at a specific index into an array function insertElement() { let array = [1, 2, 3, 4]; // index to add to let index = 3; // element that you want to add let element = 8; for (let i = array.length; i > index; i--) { //shift the elements that are greater than index ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › insert-elements-in-a-js-array
JavaScript - Insert Element in an array - GeeksforGeeks
July 23, 2025 - Refer to this article for more methods. To insert an element at a specific index, the splice() method can be used. This method allows adding elements at any position in the array while optionally removing existing ones.
🌐
W3docs
w3docs.com › javascript
How to Insert an Item into an Array at a Specific Index
In the example, we create an array and add an element to it into index 2: ... let arr = []; arr[0] = "Javascript"; arr[1] = "Python"; arr[2] = "C#"; arr[3] = "Java"; console.log(arr.join()); arr.splice(2, 0, "C++"); console.log(arr.join());
🌐
Plain English
plainenglish.io › blog › insert-an-element-in-specific-index-in-javascript-array
Insert an Element in Specific Index in JavaScript Array
November 11, 2019 - We have some in-built methods to ... → Add an element to the beginning of an array. To add an element to the specific index there is no method available in Array object....
🌐
Maslosoft
maslosoft.com › knowledge base › how to add array element at specific index in javascript?
How to add array element at specific index in JavaScript?
September 10, 2020 - Passing as parameter on integer value greater than zero, results in adding element before that index value. var x = [111, 222, 333]; x.splice(2, 0, 666); // Array is now [111, 222, 666, 333] If we set index parameter to be greater than maximum existing array index or negative value, the new element will be appended to end of array. However good practice is to avoid such constructs, instead use array.length or better push method.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-inserting-multiple-items-at-specific-index-in-js-array
JavaScript – Inserting Multiple Items at Specific Index in JS Array | GeeksforGeeks
November 15, 2024 - We can insert an item into Array at a specific index using the JavaScript Array splice method. This method removes the elements from the mentioned index and add items at that specific position.
🌐
Fjolt
fjolt.com › article › javascript-how-to-insert-at-index-array
Inserting an Item into an Array at a Specific Index in Javascript
Any data inserted in the third argument (or any argument after the third argument) is added to the array at the specified index. Here is another example, where we insert ‘broccoli’ into an array at index 2: let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ]; // Inserts broccoli at position 2, after deleting 0 items arr1.splice(2, 0, 'broccoli'); // Returns [ 'potato', 'banana', 'ravioli', 'brccoli', 'carrot' ] console.log(arr1); ... Javascript loops: for vs forEach vs for..
🌐
Vultr Docs
docs.vultr.com › javascript › examples › insert-item-in-an-array
JavaScript Program to Insert Item in an Array | Vultr Docs
December 17, 2024 - This adds 'yellow' and 'pink' starting at index 2. This action demonstrates splice()’s capability to insert multiple items at once. Recognize that push() adds items to the end of an array.
🌐
David Walsh
davidwalsh.name › array-insert-index
Array: Insert an Item at a Specific Index with JavaScript
July 25, 2014 - Array.prototype.insert = function (index, item) { this.splice(index, 0, item); }; I've tinkered around quite a bit with arrays, as you may have noticed: ... Arrays are super useful -- JavaScript just makes some tasks a bit more ... code-heavy ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-insert-an-element-into-an-array-in-javascript
Push into an Array in JavaScript – How to Insert an Element into an Array in JS
November 7, 2024 - The start_position specifies the index of where we want the new elements to be inserted in the array. If there are multiple elements, it specifies where the elements inserted will start.
🌐
Medium
habtesoft.medium.com › add-elements-to-an-array-in-javascript-a9cc6cd9469f
Add elements to an array in JavaScript | by habtesoft | Medium
October 18, 2024 - In this example, we have an array of colors and we use the splice() method to add a single element and multiple elements at a specified index. ... The concat() method can also be used to add elements to an array in JavaScript.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript | MDN
Instead, we store the collection on the object itself and use call on Array.prototype.push to trick the method into thinking we are dealing with an array—and it just works, thanks to the way JavaScript allows us to establish the execution context in any way we want. ... const obj = { length: 0, addElem(elem) { // obj.length is automatically incremented // every time an element is added.