删除数组中指定的某个元素

/**
 * 删除数组中指定的某个元素,传入元素值
 * @param val
 */
Array.prototype.remove = function(val) {

    // 如果IE8不支持indexOf则加上这个方法
    if (!Array.prototype.indexOf)
    {
        Array.prototype.indexOf = function(elt /*, from*/)
        {
            var len = this.length >>> 0;
            var from = Number(arguments[1]) || 0;
            from = (from < 0)
                ? Math.ceil(from)
                : Math.floor(from);
            if (from < 0)
                from += len;
            for (; from < len; from++)
            {
                if (from in this &&
                    this[from] === elt)
                    return from;
            }
            return -1;
        };
    }

    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
原文地址:https://www.cnblogs.com/lqcdsns/p/5584534.html