I am looking for a JavaScript array insert method, in the style of:
arr.insert(index, item)
Preferably in jQuery, but any JavaScript implem
You can implement the Array.insert method by doing this:
Array.insert
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' ]