Files
portfolio/app/utils/findBy.ts
T

4 lines
193 B
TypeScript

// Find an item in `items` array, given a specific key/value.
export const findBy = <T>(key: keyof T, value: T[keyof T], items: T[]): T | undefined =>
items.find((obj) => obj[key] === value)