JSFiddle - React, Tailwind, and code Playground
by javajosh
HTML
<h1></h1>
<p>Wanted to see {"a":{"b":{"c":{"d":{}}}}}</p>
JavaScript
function select(selector, obj){
var path = selector.split('.');
var prop = null;
while (path.length > 0){
prop = path.shift();
if (!obj.hasOwnProperty(prop)){
obj[prop] = {};
}
obj = obj[prop];
}
return obj;
}
var foo = {a: {b: {c: 42}}};
var result = select('a.b.c.d', foo);
console.log(foo);
$('h1').text(JSON.stringify(foo));