Hapus duplikat dengan ID

interface MyArray {
  id: string;
  name: string;
}

const arr: MyArray[] = [{id: '1', name: 'name'}, {id: '2', name: 'name2'}, {id: '3', name: 'name3'}];


const removeDuplicates = <T extends {id: string}>(array: T[]) =>
  array.reduce((acc: T[], item) => [...acc.filter(({ id }) => id !== item.id), item], []);

removeDuplicates(arr);
Outrageous Octopus