Skip to content

Instantly share code, notes, and snippets.

@mbrown3321
Created October 17, 2020 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrown3321/a9fc8ce2b29f5df830dc8233e78376f2 to your computer and use it in GitHub Desktop.
Save mbrown3321/a9fc8ce2b29f5df830dc8233e78376f2 to your computer and use it in GitHub Desktop.
let dictionary = users.reduce((acc, u) => ({
...acc,
[u.id]: u
}), {});
// {
// "1": {
// "id": 1,
// "name": "Michael Scott",
// "loginCount": 123,
// "active": false
// },
// "2": {
// "id": 2,
// "name": "Dwight Schrute",
// "loginCount": 776655,
// "active": true
// },
// "3": {
// "id": 3,
// "name": "Jim Halpert",
// "loginCount": 75,
// "active": true
// },
// "4": {
// "id": 4,
// "name": "Ryan Howard",
// "loginCount": 2,
// "active": false
// },
// "5": {
// "id": 5,
// "name": "Darryl Philbin",
// "loginCount": 33,
// "active": true
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment