js 删除数组指定下标或指定对象

来源:互联网 发布:华润置地 数据分析 编辑:程序博客网 时间:2024/05/19 14:53
/**
 *删除数组指定下标或指定对象
 */
Array.prototype.remove = function(obj) {
    for (var i = 0; i < this.length; i++) {
        var temp = this[i];
        if (!isNaN(obj)) {
            temp = i;
        }
        if (temp == obj) {
            for (var j = i; j < this.length; j++) {
                this[j] = this[j + 1];
            }
            this.length = this.length - 1;
        }
    }
}
原创粉丝点击