zoukankan      html  css  js  c++  java
  • Javascript common functions

    The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.       

    1. Array.prototype.removeAt = function (index) {
       var part1 = this.slice(0, index);
       var part2 = this.slice(index + 1);
       return part1.concat(part2);

    }

    var a = [10, 11,12,13];
    a.removeAt(2); // remove 12

    2. Array.prototype.indexOf = function (what, i) {
        i = i || 0;
        var L = this.length;
        while (i < L) {
            if (this[i] === what) return i;
            ++i;
        }
        return -1;
    }

    3. 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;
    }

  • 相关阅读:
    获取系统版本
    一句代码删除所有子视图
    MAJOR-MINOR-MKDEV
    AF_UNIX和AF_INET域的socket在epoll中的差异
    python-print
    python-class(5)
    python-class(4)
    python-class(3)
    python-class(2)
    python-class(1)
  • 原文地址:https://www.cnblogs.com/webglcn/p/2642374.html
Copyright © 2011-2022 走看看