let arr=[1,[1,2,3,[1,2,3,4,[4,5,6,[6,7,8]]]]] console.log(…new Set(arr.flat(Infinity).sort((a,b)=>{a-b})))