Nodejs Array Insert After insertAfter(index, item)

Here you can find the source of insertAfter(index, item)

Method Source Code

// Insert an item into an array after the index passed.
// Can throw "Index out of range" error.
Array.prototype.insertAfter = function(index, item) {
    if (index > this.length - 1 || index < 0) {
        throw new Error("Index out of range");
    }/*from w  w w  .j a  v a 2 s. com*/
    this.splice(index + 1, 0, item);
};

Related

  1. insertAfter(o, toInsert)
    Array.prototype.insertAfter = function (o, toInsert) {
        var inserted = false;
        var index = this.indexOf(o);
        if (index == -1) {
            return false;
        else {
            if (index == this.length - 1) {
                this.push(toInsert);
    ...