Created
June 6, 2023 15:24
-
-
Save ernestlv/a0aca693db32a10255df7b3d0bcffd89 to your computer and use it in GitHub Desktop.
convert arr to map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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