Skip to content

Instantly share code, notes, and snippets.

@mapsi
Created August 9, 2022 02:43
Show Gist options
  • Save mapsi/3ec5f7b8ef77639f1561fc2b8e66f8cd to your computer and use it in GitHub Desktop.
Save mapsi/3ec5f7b8ef77639f1561fc2b8e66f8cd to your computer and use it in GitHub Desktop.
Recursive map to object
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