I'm doing some data cleaning in Javascript, and I was wondering if there is a way to combine objects based on a common ID.
Given the following:
{"subject":"Hadji Singh","predicate":"nameOfUser","id":"3f540200-58b9-40a5-91c2-faafec75216f"}
{"subject":"Race Roger Bannon","predicate":"nameOfUser","id":"41376a49-34ee-4ed8-b5f5-3f8c92b107f8"}
{"subject":"Jessie Bannon","predicate":"nameOfUser","id":"9575cf33-8992-4763-81bb-fc640ffa3545"}
{"subject":"Adventurer","predicate":"departmentOfUser","id":"3f540200-58b9-40a5-91c2-faafec75216f"}
{"subject":"Bodyguard","predicate":"departmentOfUser","id":"41376a49-34ee-4ed8-b5f5-3f8c92b107f8"}
{"subject":"Adventurer","predicate":"departmentOfUser","id":"9575cf33-8992-4763-81bb-fc640ffa3545"}
Is there a way to turn it into something like this?
[{id:3f540200-58b9-40a5-91c2-faafec75216f, name:Hadji Singh, department:Adventurer},
{id:9575cf33-8992-4763-81bb-fc640ffa3545, name:Jessie Bannon, department:Adventurer},
{id:41376a49-34ee-4ed8-b5f5-3f8c92b107f8, name:Race Bannon, department:Bodyguard}]
I'm thinking of two for loops (maybe) and a lot of if's, but perhaps there's some way I'm missing.
I'm using node.js, if that means anything. Perhaps there's a module that can help?
Thanks.