zoukankan      html  css  js  c++  java
  • js代码段

    1、数组去重

    Array.prototype.DuplicateRemoval = function(){
        let res = [this[0]];
        for(let i = 1; i < this.length; i++){
            var repeat = false;
            for(let j = 0; j < res.length; j++){
                if(this[i] == res[j]){
                    repeat = true;
                    break;
                }
            }
            if(!repeat){
                res.push(this[i]);
            }
        }
     return res;
    }
    var arr = [1, '1', '1', 'b', 'd', 'e', 'e', 1, 0]
    console.log(arr.DuplicateRemoval());

     2、页面刷新前触发

    window.addEventListener("beforeunload", function(event) {
      event.returnValue = "You may have unsaved Data";
    });
  • 相关阅读:
    内部类
    this关键字
    封装
    构造方法
    类图
    StringBuffer
    String
    导包
    包名规范
    带参数的方法
  • 原文地址:https://www.cnblogs.com/guojikun/p/6845996.html
Copyright © 2011-2022 走看看