I have an array of objects called "directory" which include a list of people and their job. The problem is that a person can cover more than 1 role and I'd like to group the "job" under the same "id" during rendering. This is my array:
"directory":
[
{
"id": 37,
"job": "Electrician",
"name": "Alan"
},
{
"id": 32,
"job": "Writer",
"name": "Mark"
},
{
"id": 37,
"job": "DIY",
"name": "Alan"
},
{
"id": 134,
"job": "Director",
"name": "Philip"
},
{
"id": 37,
"job": "Plumber",
"name": "Alan"
},
{
"id": 85,
"job": "Teacher",
"name": "Oliver"
},
]
and I'd like to get a new array to display as:
Alan: Electrician, Plumber, DIY
Mark: Writer
Philip: Director,
Oliver: Teacher
I'm not sure whether I should use nested .map or reduce.
Any help appreciated.