I have an array of Javascript objects like below.
[{
"email": "alex@test.com",
"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": "mike@test.com",
"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": "fred@test.com",
"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": "alex@test.com",
"fn": "Alex",
"sn": "McPherson",
"phone": "01233xxxxx",
"hours": "90",
"rate": "30",
"amount": "900",
"vat": "120",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}]
What I ideally want is to group those of the same value (email) into there own sub array of objects i.e if you look at the array above you will see I have 2 entries for the same person Alex McPherson. What I want to do is the below if possible move and combine into a sub array and the same for any other value that exists more than once.
[[{
"email": "alex@test.com",
"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": "alex@test.com",
"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": "mike@test.com",
"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": "fred@test.com",
"fn": "Fred",
"sn": "Frogg",
"phone": "01233xxxxx",
"hours": "80",
"rate": "90",
"amount": "800",
"vat": "100",
"agency": "test",
"start": "08/06/2017",
"end": "10/06/2017"
}]]
I can't seem to get my head around resorting the array.