編寫(xiě)一個(gè)程序?qū)?shù)組扁平化去并除其中重復(fù)部分?jǐn)?shù)據(jù),最終得到一個(gè)升序且不重復(fù)的數(shù)組
var arr = [ [1, 6, 2], [3, 2, 5, 5], [6, 9, 8, 9, [11, 9, [12, 13, [14] ] ] ], 8];
var newArr1 = arr.toString()
var newArr2 = arr.toString().split(',')
console.log("新數(shù)組",newArr1);//1,6一忱,2,3彬坏,2嘉赎,5,5亩冬,6艘希,9,8硅急,9覆享,11,9营袜,12撒顿,13,14荚板,8
console.log("新數(shù)組",newArr2);//['1'凤壁,'6','2'跪另,'3'拧抖,'2','5'免绿,'5'唧席,'6','9'嘲驾,'8'淌哟,'9','11'距淫,'9'绞绒,'12','13'榕暇,'14','8']
var newArr = arr.toString().split(',').sort(function(a,b){
return a-b
}).map(Number)
let finarr = Array.from(new Set(newArr))
console.log("新數(shù)組",newArr,finarr);
new Set(newArr); 將數(shù)組去重并返回一個(gè)對(duì)象;
Array.from(obj);? 將對(duì)象轉(zhuǎn)換成數(shù)組