JSFiddle - React, Tailwind, and code Playground
JavaScript
var obj1 = {
"one": {
"propOne": 1,
"propTwo": {
"innerProp": "hello"
}
},
"two": {
"twoProp": "something",
"twoProp2": {
"inside": "world",
"deep": {
"end": "ok"
}
}
}
};
function isObject(obj) {
'use strict';
var result = false;
if (typeof obj === 'object' && obj !== null && Object.keys(obj).length > 0) {
result = true;
}
return result;
}
function recurse(obj, key) {
'use strict';
key = key || '';
if (isObject(obj)) {
for (var k in obj) {
if (isObject(obj[k])) {
var dot = key ? '.' : '';
key += key ? '.' + recurse(obj[k], k) : recurse(obj[k], k);
} else {}
}
}
return key + ',';
}
console.log(recurse(obj1));