Nodejs Array Insert Before insertBefore(index, item)

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

Method Source Code

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

Related

  1. insertBefore(o, toInsert)
    Array.prototype.insertBefore = function (o, toInsert) {
        var inserted = false;
        var index = this.indexOf(o);
        if (index == -1) {
            return false;
        else {
            if (index === 0) {
                this.unshift(toInsert);
    ...