1 数组操作
1.1 数组去重:ES6的方法
//ES6新增的Set数据结构,类似于数组,但是里面的元素都是唯一的 ,其构造函数可以接受一个数组作为参数
//let arr=[1,2,1,2,6,3,5,69,66,7,2,1,4,3,6,8,9663,8]
//let set = new Set(array);
//{1,2,6,3,5,69,66,7,4,8,9663}
//ES6中Array新增了一个静态方法from,可以把类似数组的对象转换为数组
//Array.from(set)
//[1,2,6,3,5,69,66,7,4,8,9663]
function removeRepeatArray(arr) {
return Array.from(new Set(arr))
}
1.2 数组顺序打乱
function upsetArr(arr) {
return arr.sort(function() {
return Math.random() - 0.5
});
}