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";
});

 

posted @ 2017-05-12 16:12  _zhiqiu  阅读(205)  评论(0编辑  收藏  举报