JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<input type="text" name="id1"/>
<input type="text" name="id2"/>
<input type="text" name="levelTwo1"/>
<input type="text" name="levelTwo2"/>
<input type="text" name="levelTwo3"/>
</body>
JavaScript
var Obj = {
id1: 'stuff',
id2: 'things',
id3: {
levelTwo1: 'moreStuff',
levelTwo2: 'morethings',
levelTwo3: 'morestuff-n-things'
}
}
function addAttributeInput(obj) {
for (var o in obj) {
if (typeof obj[o] == "object") {
addAttributeInput(obj[o]);
} else {
$("input[name='" + o + "']").val(obj[o]);
}
}
}
addAttributeInput(Obj);