I have an array of objects which are set up like so:
{ code: 1
description: "ARTICLES OF AGREEMENT"
disciplineId: "d29b2d98-39c6-4350-3bd5-08dac6565a75"
id: "783d6788-19f2-4cbd-79b3-08dac6565a77"
projectSchedules: []
r6Codes : []
r7Codes: []
scheduleMaterials: []
}
and so on for the rest of them. This is stored in an array called schedulesList.
In this array there will be objects which are identical apart from the disciplineId. What am I trying to do is remove the ones that are identical but don't have a specific disciplineId
I had tried to do this by creating an array of objects that I wanted to remove called scheduleToRemove and then do:
for(let i = 0; i< schedulesToRemove.length; i++) {
scheduleList.splice(scheduleList.indexOf(schedulesToRemove[i]));
}
However, this is only removing one duplicate and the rest remain there. So is there a simpler way of going about this?
Edit:
So schedulesToRemove will have all the objects I need removed schedulesList, so for example, it contains:
{ code: 350
description: "SUPPLY, FABRICATE AND ERECT LADDER RACK INCLUDING ALL ACCESSORIES"
disciplineId: "eb89ae1d-db9a-41ee-3bdb-08dac6565a75"
id: "87b19612-d03a-4ce0-79f5-08dac6565a77"
projectSchedules: []
r6Codes : []
r7Codes: []
scheduleMaterials: []
}
scheduleList will also have this but also one like:
{ code: 350
description: "SUPPLY, FABRICATE AND ERECT LADDER RACK INCLUDING ALL ACCESSORIES"
disciplineId: "2f33be5c-f3fa-4c50-3bda-08dac6565a75"
id: "87b19612-d03a-4ce0-79f5-08dac6565a77"
projectSchedules: []
r6Codes : []
r7Codes: []
scheduleMaterials: []
}
So as you can see, they are both the exact same apart from disciplineId having a different value. So I would want to remove the first one but keep the second one