Javascript Array removeAt(index)

Description

Javascript Array removeAt(index)



Array.prototype.removeAt = function (index)
{
    if (this.length <= index || index < 0)
    {/*from   w w  w .  j  ava 2  s  .  c  o m*/
        return;
    }
    for (var i = index + 1, n = index; i < this.length; ++i, ++n)
    {
        this[n] = this[i];
    }
    this.pop();
}

Javascript Array removeAt(index)

"use strict";//  w w  w .  ja  v a2  s .c  om



Array.prototype.removeAt = function(index) {
    this.splice(index, 1);
    return this;
};

Array.prototype.print = function() {
    for (var i = 0; i < this.length; i++) {
        console.log(this[i] + ", ");
    }
};
Array.prototype.remove = function() {
    var what, a = arguments,
        L = a.length,
        ax;
    while (L && this.length) {
        what = a[--L];
        while ((ax = this.indexOf(what)) !== -1) {
            this.splice(ax, 1);
        }
    }
    return this;
};

Javascript Array removeAt(index)

//todo: remove all references to these functions

Array.prototype.removeAt = function(index) {
    var arr = this;
    var len = arr.length;
    if (!len) return false;
    while (index < len) {
        arr[index] = arr[index+1];/*from w w  w.  ja  v a2 s. c om*/
        index++
    }
    arr.length--;
    return true;
};



PreviousNext

Related