JSFiddle - React, Tailwind, and code Playground
by Ed Bulikyan
JavaScript
var data = {
perData: {
name: 'Andrey',
county: {
borough : 'Moskow'
}
},
friends: ["Max", "Dmitriy"]
};
function log(count, key, value) {
const string = [];
string.push(
''.padStart(count, "-"),
key
);
string.push(': ')
if (typeof value != 'object') {
string.push(value);
}
console.log(string.join(''))
}
function builtTree(obj, count) {
Object.keys(obj).forEach(key => {
log(count, key, obj[key]);
if (typeof obj[key] === "object") {
count++;
builtTree(obj[key], count);
}
});
}
builtTree(data, 1);