数组扁平化,去重,排序

把数组var arr =  [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];  扁平化,去重,并排序。

var result = [...new Set(arr.flat(Infinity))].sort((a, b) => a - b); 

arr.flat 用来扁平化

new Set用来去重

sort用来排序

发布了180 篇原创文章 · 获赞 16 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/liubangbo/article/details/104290658