Created
March 24, 2023 22:49
-
-
Save gn-bcampbell/60b917c756e047c968bdf0db4f1c275f to your computer and use it in GitHub Desktop.
Loop over response, remove duplicates inside property array of objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface SetActivityDetails { | |
Id: number | |
Description: string | |
SetId: number | |
SetType: string | |
SetVisitId: number | |
CostAttributionId?: number | |
} | |
export type RequestErrorResponse = Array<{ | |
field: string | |
tab: string | |
unknownActivities: SetActivityDetails[] | |
}> | |
// create a new set and map values on their description comparing them to index each iteration | |
response.data.forEach((field) => { | |
const uniqueActivity = [ | |
...new Set(field.unknownActivities.map((item) => item.itemId)), | |
].map((id) => { | |
return { | |
itemId: id, | |
setName: field.unknownActivities | |
.filter((item) => item.itemId === id) | |
.map((item) => item.description) | |
.filter((name, index, arr) => arr.indexOf(name) === index), | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment