Nodejs Utililty Methods Array Insert Before

List of utility methods to do Array Insert Before

Description

The list of methods to do Array Insert Before are organized into topic(s).

Method

insertBefore(index, item)
Array.prototype.insertBefore = function(index, item) {
    if (index > this.length - 1 || index < 0) {
        throw new Error("Index out of range");
    this.splice(index, 0, item);
};
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);
...