我有一个 Javascript 对象数组,如下所示。
[{
"email": "[email protected]",
"fn": "Alex",
"sn": "McPherson",
"phone": "01233xxxxx",
"hours": "40",
"rate": "20",
"amount": "200",
"vat": "60",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
},
{
"email": "[email protected]",
"fn": "Mike",
"sn": "Mann",
"phone": "01233xxxxx",
"hours": "50",
"rate": "70",
"amount": "500",
"vat": "90",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
},
{
"email": "[email protected]",
"fn": "Fred",
"sn": "Frogg",
"phone": "01233xxxxx",
"hours": "80",
"rate": "90",
"amount": "800",
"vat": "100",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
},
{
"email": "[email protected]",
"fn": "Alex",
"sn": "McPherson",
"phone": "01233xxxxx",
"hours": "90",
"rate": "30",
"amount": "900",
"vat": "120",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}]
我理想的情况是将那些具有相同值(电子邮件)的对象分组到自己的对象子数组中,即如果您查看上面的数组,您会看到我有同一个人亚历克斯·麦克弗森的两个条目。我想要做的是,如果可能的话,将下面的内容移动并组合到一个子数组中,对于多次存在的任何其他值也是如此。
[[{
"email": "[email protected]",
"fn": "Alex",
"sn": "McPherson",
"phone": "01233xxxxx",
"hours": "40",
"rate": "20",
"amount": "200",
"vat": "60",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
},{
"email": "[email protected]",
"fn": "Alex",
"sn": "McPherson",
"phone": "01233xxxxx",
"hours": "90",
"rate": "30",
"amount": "900",
"vat": "120",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}],
[{
"email": "[email protected]",
"fn": "Mike",
"sn": "Mann",
"phone": "01233xxxxx",
"hours": "50",
"rate": "70",
"amount": "500",
"vat": "90",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}],
[{
"email": "[email protected]",
"fn": "Fred",
"sn": "Frogg",
"phone": "01233xxxxx",
"hours": "80",
"rate": "90",
"amount": "800",
"vat": "100",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}]]
我似乎无法集中精力使用阵列。