Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
3 of 4
added 2 characters in body
K.Dᴀᴠɪs

You can implement the Array.insert method by doing this:

Array.prototype.insert = function ( index, item ) {
    this.splice( index, 0, item );
};

Then you can use it like:

var arr = [ 'A', 'B', 'D', 'E' ];
arr.insert(2, 'C');

// => arr == [ 'A', 'B', 'C', 'D', 'E' ]
FrEsC 81