Created
August 9, 2022 02:43
-
-
Save mapsi/3ec5f7b8ef77639f1561fc2b8e66f8cd to your computer and use it in GitHub Desktop.
Recursive map to object
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
const mapToObj = (m) => | |
Array.from(m).reduce( | |
(obj, [key, value]) => ({ | |
...obj, | |
[key]: value instanceof Map ? mapToObj(value) : value, | |
}), | |
{}, | |
); | |
export default { mapToObj }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment