JSFiddle - React, Tailwind, and code Playground
JavaScript
function stringToObj(path, obj) {
var parts = path.split(".");
var part;
while ((part = parts.shift())) {
if (typeof obj[part] != "object") obj[part] = {};
obj = obj[part]; // line 6
}
}
let result = {};
stringToObj("a.b.c", result);
console.log(result); // outputs the json