Table of contents
No headings in the article.
let myObj = {
name: 'hari',
location: {
city: 'hyderabad'
},
a: {
b: {
c: {
d: {
e: {
f: {
g: {
h: {
i: 10
}
}
}
}
}
}
}
}
};
let count = 0;
function countDepth (myObj) {
for (let object in myObj) {
if (typeof myObj[object] === 'object') {
countDepth(myObj[object]);
count++;
}
}
return count;
}
console.log(countDepth(myObj));
Output:
9