Skip to content

Instantly share code, notes, and snippets.

@aercolino
Created January 23, 2020 13:26
Show Gist options
  • Save aercolino/98cf08b83bf098213a09725425bff48e to your computer and use it in GitHub Desktop.
Save aercolino/98cf08b83bf098213a09725425bff48e to your computer and use it in GitHub Desktop.
function convertDottedKeyToObject(name, value) {
return name.split('.').reverse().reduce((acc, key) => ({ [key]: acc }), value);
}
JSON.stringify(convertDottedKeyToObject('it.is.a', 'one liner'), null, 2)
"{
"it": {
"is": {
"a": "one liner"
}
}
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment