title: How to check the depth of an object?
body: <p>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 has been asked before, couldn't find it.</p>
  
  <p>If I have this object:</p>
  
  <pre><code>{foo:{bar:{baz : 'baa'}}}
  </code></pre>
  
  <p>I need it to return 3, it has 3 levels to it.</p>
  
  <p>With this object:</p>
  
  <pre><code>{abc: 'xyz'} 
  </code></pre>
  
  <p>It would have to be 1. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>utils.depthOf = function(object, level){
      // Returns an int of the deepest level of an object
      level = level || 1;
  
      var key;
      for(key in object){
          if (!object.hasOwnProperty(key)) continue;
  
          if(typeof object[key] == 'object'){
              level++;
              level = utils.depthOf(object[key], level);
          }
      }
  
      return level;
  }
  </code></pre>
  
  <p>The problem is it counts sister elements too. It's actually not getting depth, it's counting all members of an object. </p>