Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Created June 6, 2023 15:24
Show Gist options
  • Save ernestlv/a0aca693db32a10255df7b3d0bcffd89 to your computer and use it in GitHub Desktop.
Save ernestlv/a0aca693db32a10255df7b3d0bcffd89 to your computer and use it in GitHub Desktop.
convert arr to map
/* converts an array of the form [ { key, value } ] to a map of the form { key:value } */
const arr = [{key:"123", value:"abc"}, {key:"456", value:"def"}, {key:"789", value:"ghi"}];
const map = arr.reduce((res, o) => ({ ...res, [o.key]:o }), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment