Skip to content

Instantly share code, notes, and snippets.

View aercolino's full-sized avatar

Andrea Ercolino aercolino

View GitHub Profile
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"