Created
January 23, 2020 13:26
-
-
Save aercolino/98cf08b83bf098213a09725425bff48e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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