deduplicate-array.ts
1 /** 2 * Checks value of `key` of each object in an array, and returns an array 3 * of de-duplicated objects based on the value of `key`. 4 * @param array The array to de-duplicate. 5 * @param key The key to check for de-duplication. 6 * @returns The de-duplicated array. 7 */ 8 export default function <T>(array: T[], key: keyof T): T[] { 9 return [...new Map(array.map((item) => [item[key], item])).values()]; 10 }