数组扁平化(多维数组)(es6)
const flatArray = arr => arr.reduce((a,b) =>a.concat(Array.isArray(b) ? Flat(b) : b),[] )
console.log(flatArray([1,2,[1,2]]))
数组去重 (es6)
let arr = [1,2,3,1,2]
Array.from(new Set(arr))
数组去重(es5)
function dedupe(arr) {
let result = [];
arr && arr.forEach(item => {
if (!result.includes(item)) {
result.push(item);
}
})
return result
}
console.log(dedupe([1,2,3,1,2]))
网友评论