Skip to content

Instantly share code, notes, and snippets.

@josgraha
Created January 7, 2021 15:50
Show Gist options
  • Save josgraha/60ab6dd7080a870b95a4f466c3706b60 to your computer and use it in GitHub Desktop.
Save josgraha/60ab6dd7080a870b95a4f466c3706b60 to your computer and use it in GitHub Desktop.
JavaScript Map to Object
const _ = require('lodash');
mapToObject = m => _.isMap(m) ? [...m].reduce((o, entry) => ({...o, ...{ [_.head(entry)]: mapToObject(_.head(_.tail(entry))) }}), {}) : m;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment