There are several arrays of objects in different types listed below.
item: Item[] = [{id: 1, name: 'item 1'}]
product: Product[] = [{id: 1, name: 'product 1'}]
To remove objects from these arrays, I am looking to create a versatile function that will be an arrow function with generics and can be exported from another .ts
file. This way, I can delete items from any array using the same function.
I attempted the following approach:
export const removeFromArray = <T>(arr: T[], value: any) => {
return arr.filter((val: T) => val['id'] !== value)
}