JavaScript.Remove

Array.prototype.remove = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this.rest);
};

array.remove(0);//删除第一个元素
array.remove(-1);//删除倒数第一个元素
array.remove(0,2);//删除数组下标为0-2的元素(3个)
posted @ 2016-04-12 20:55  shidengyun  阅读(523)  评论(0编辑  收藏  举报