JS数组添加不重复元素

2020-02-05 22:47:44

prototype. 属性是所有对象中的一个基本属性,他能使对象添加新的属性方法

arguments 实参,js中参数的传递都是通过arguments数组(并不是Arrays的实现类)来遍历出参数的个数

indexof() 方法,索引方法,如果不存在,返回-1;

push() 原生数组在末尾添加参数,返回一个新的数组

Array.prototype.pushNoRepeat = function () {
        for (var i = 0; i < arguments.length; i++) {
            var ele = arguments[i];
            if (this.indexOf(ele) == -1) {
                this.push(ele);
            }
        }
    };


  • 2018-01-01 10:50:49

    仿QQ长按弹出功能菜单

    android app普遍常用的弹出上下文菜单是列表式的。QQ列表,在上方弹出冒泡效果菜单,如图