So I have an array of objects and I am trying to remove the duplicates. For example, lets say my array of object contains this data:
[{TERM_CD: "220181", CRS_SUBJ_CD: "LALS", CRS_SUBJ_DESC: "Latin American &Latino Studies", CRS_NBR: "127", CRS_TITLE: "Latin American Music", …},
{TERM_CD: "220101", CRS_SUBJ_CD: "MUS", CRS_SUBJ_DESC: "Music", CRS_NBR: "127", CRS_TITLE: "Latin American Music", …}, etc...]
And this is the removeDup function that I am using to remove duplicates:
removeDup(data, key) {
return [
...new Map(
data.map(x=>[key(x), x])
).values(),
];
}
For example if I call the remove dup function like this then one of the object will be removed since they both have same crs_title.
const noDupArr = this.removeDup(printArr, x => x.CRS_TITLE);
So my goal is to try to remove duplicate on 2 keys CRS_SUBJ_CD and CRS_NBR but I am not able to figure out how to proceed doing that. I tried adding another key parameter in the removeDup function but wasn't successful. Any ideas on fixing this issue. Thank you in advance!