Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
4 of 4
splice allows more, why shouldn't this
AMJ

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

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

Then you can use it like:

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

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