How can I create two of same object for same array each pass through .map?
Have a data set like the following:
data = [
{initiatorRole: "dispatch", receiverRole: "police"},
{initiatorRole: "dispatch", receiverRole: "fire"},
{initiatorRole: "police", receiverRole: "dispatch"}
]
I would like to get these into a single set of objects where I will remove duplicates and add additional data.
roles = [
{role: "dispatch"},
{role: "police"},
{role: "dispatch",
{role: "fire"},
{role: "police"},
{role: "dispatch"}
]
The code I currently have:
roles = data.map(d => {
let rObj = {}
rObj["id"] = d.initiatorRole
rObj["id"] = d.receiverRole
return rObj;
});
But of course this just returns the last rObj set. Can this be done with a single map call?