var arr = [[1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14]]]], 10];
var newArray = [];
function getArray(array) {
array.forEach(function(e) {
if (typeof e === "object") {
getArray(e);
} else {
newArray.push(e);
}
});
}
getArray(arr);
Array.prototype.distinct = function() {
return this.reduce(function(newArray1, newValue) {
if (newArray1.indexOf(newValue) === -1)
newArray1.push(newValue);
return newArray1;
}, []);
};
newArray = newArray.distinct();
newArray.sort(function(a, b) {
return a - b;
});
js扁平化数组去重 超屌的
最新推荐文章于 2024-03-21 05:04:05 发布