Skip to content

Instantly share code, notes, and snippets.

@gn-bcampbell
Created March 24, 2023 22:49
Show Gist options
  • Save gn-bcampbell/60b917c756e047c968bdf0db4f1c275f to your computer and use it in GitHub Desktop.
Save gn-bcampbell/60b917c756e047c968bdf0db4f1c275f to your computer and use it in GitHub Desktop.
Loop over response, remove duplicates inside property array of objects
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