Guest User

Untitled

a guest
Jan 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. // want to be able to ensure that the second param (key) exists as a key on the objects of the first type (array)
  2.  
  3. export const arrayToKeyedObj = (array: Array<{}>, key: string): {} => {
  4. return array.reduce((acc, item) => {
  5. acc[item[key]] = item
  6. return acc
  7. }, {})
  8. }
Add Comment
Please, Sign In to add comment