Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // want to be able to ensure that the second param (key) exists as a key on the objects of the first type (array)
- export const arrayToKeyedObj = (array: Array<{}>, key: string): {} => {
- return array.reduce((acc, item) => {
- acc[item[key]] = item
- return acc
- }, {})
- }
Add Comment
Please, Sign In to add comment