思路:使用flat函数将数组扁平化,再使用Set去除重复项,最后使用sort排序
let arr = [12, 25, 25, [45, 55], [45, [25], 2]];
//数组扁平化 如果不管有多少层嵌套,都要转成一维数组,可以用Infinity关键字作为参数。
let arry = arr.flat(Infinity);
arry = [...new Set(arry)];
arry.sort((m, n) => {
return m - n;
});
console.log(arry);