SHARE
TWEET

Untitled

a guest Sep 16th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Like array.map, but for objects
  2. const mapObj = <U, T extends object>(
  3.   obj: T,
  4.   mapFn: (val: T[keyof T], key?: keyof T) => U
  5. ): { [K in keyof T]: U } => {
  6.   return Object.assign(
  7.     {},
  8.     ...Object.entries(obj).map(([k, v]) => ({ [k]: mapFn(v, k as keyof T) }))
  9.   );
  10. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top