JSFiddle - React, Tailwind, and code Playground

by amirnissim

JavaScript

var dot = '.';

function buildObj(s) {
    var
    parts = s.split(dot),
        key = parts[0],
        o = {};

    if (parts.length === 2) {
        o[key] = parts[1];
        return o;
    }

    o[key] = buildObj(parts.slice(1).join(dot));
    return o;
}

var o = buildObj('key.with.dot.value');
// alert(JSON.stringify(o));