var arr = [
{a: "b"},
{a: "b"},
{a: "c"},
{a: "c"}
];
var arr2 = [];
var arr3 = [];
Object.keys(arr).forEach(key => {
Object.keys(arr[key]).forEach(keyx => {
if (!(arr[key][keyx] in arr2)) {
arr2[arr[key][keyx]] = [];
}
var k = keyx;
var x = 1;
var i = true;
while (i === true) {
if (!(k in arr2[arr[key][keyx]])) {
i = false;
arr2[arr[key][keyx]][k] = arr[key][keyx];
}
k = keyx + x;
x++;
}
})
});
for (i in arr2) {
arr3.push(arr2[i]);
}
//arr3 is the expected array
1条答案
按热度按时间u5i3ibmn1#
希望这会有所帮助: