ES6数组去重、快速去重排序

new Set()方法

vararr = [1,2,1,2,3,4,5,6,6,9,9,8]; console.log(new Set(arr))

Array.from(new Set(arr))方法
vararr = [1,2,1,2,3,4,5,6,6,9,9,8]; console.log(Array.from(new Set(arr))

【ES6数组去重、快速去重排序】BFC:块级元素格式化上下文
浅拷贝
vara = { name = 1 } b=a; b.name = 2 console.log(a) //2

深拷贝
var newObj = {}; function deepCopy(obj,newObj){ for(var i in obj){ if(typeof(obj[i]) === "object"){//判断这个是否为对象或者是数组 newObj[i] = Array.isArray(obj[i])?[]:{}; //newObj.arr={} deepCopy(obj[i],newObj[i]); //用递归把数组或者数组中的每一个元素遍历出来 }else{ newObj[i] = obj[i]; //newObj.name=bgg } } return newObj; } var res = deepCopy(obj1,newObj); console.log(res); //改变obiect res.skill = function(){ console.log("9999"); } obj1.skill(); res.skill(); res.arr[0] = "888"; console.log(obj1.arr); console.log(res.arr);

    推荐阅读