I\'m working on a permissions system with variable depth; depending on the complexity of a page, there could be more or less levels. I searched StackOverflow to find if this
This should do it, if you wanna keep it short:
function maxDepth(object) { if (typeof object !== "object" || object === null) { return 0; } let values = Object.values(object); return (values.length && Math.max(...values.map(value => maxDepth(value)))) + 1; }