let arr = [3, 2, {a: 1}, 1, {a: 1}, 1];
function ana(arr) {
let newArr = [];
let unique = [];
for (let i of arr) {
i = JSON.stringify(i);
//如果已有数值相同的元素存在
if (unique.includes(i)) {
newArr[unique.indexOf(i)].push(i)
} else {
let arr = [];
arr.push(i);
unique.push(i);
newArr.push(arr)
}
}
return re(newArr)
}
网友评论