• Array.prototype.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);
    };


    这个函数扩展了JavaScript的内置对象Array,这样,我们以后的所有声明的数组都会自动的拥有remove能力,我们来看看这个方法的用法:
    var array = ["one", "two", "three", "four", "five", "six"];

    print(array);
    array.remove(0);//删除第一个元素
    print(array);
    array.remove(-1);//删除倒数第一个元素
    print(array);
    array.remove(0,2);//删除数组中下标为0-2的元素(3个)
    print(array);
    会得到这样的结果:
    one,two,three,four,five,six
    two,three,four,five,six
    two,three,four,five
    five

  • 相关阅读:
    oracle与DB2
    oracle ORA-01427: 单行子查询返回多个行
    mysql开发总结
    mysql show profile基本详解
    mysql批量插入数据
    mysql索引详解
    mysql性能调优
    MySQL优化
    mysql主从调优
    mysql主从复制
  • 原文地址:https://www.cnblogs.com/Mancy/p/3298810.html
Copyright © 2020-2023  润新知