1/数组的去重
//字符串的去重
var arrData=[1,2,3,2,3,4]
var list=newArr(arrData)
//数组去重--gmgm
function newArr(arr) {
return Array.from(new Set(arr))
}
console.log(list)//[1,2,3,4]
//常用循环方法
function unique(arr){
for(var i=0; i<arr.length; i++){
for(var j=i+1; j<arr.length; j++){
if(arr[i]==arr[j]){ //第一个等同于第二个,splice方法删除第二个
arr.splice(j,1);
j--;
}
}
}
return arr;
}
let allUnitList=[{id:1,name:'名称1'},{id:2,name:'名称2'},{id:3,name:'名称3'}]
let userUnit=[1,2]
allUnitList = allUnitList.filter(function (item) {
return userUnit.indexOf(item.id) < 0;
})
console.log(allUnitList)//[{id:3,name:'名称3'}]
2/将数据分割成多个数组
function arrSize(array, size) {
//得到的数组按照一定数量分割成多个数组
let [start, end, result] = [null, null, []]
for (let i = 0; i < Math.ceil(array.length / size); i++) {
start = i * size
end = start + size
result.push(array.slice(start, end))
}
console.log(result)//将数组分割后
let list = []
//再次处理分割好的数组
result.map((item, index) => {
let valueList = []
item.map((itemD, indexD) => {
valueList.push(itemD.value)
})
list.push({ name: item[0].name, value: valueList })
})
console.log(list)
return list
}
文件流下载
let blob = new Blob([code], {type: "application/vnd.ms-excel"}); // code就是接口返回的文件流了
let objectUrl = URL.createObjectURL(blob);
window.location.href = objectUrl;