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