title: How to count a depth level of nested objects?
body: <p>I have an expample array of nested objects:</p>
  
  <pre><code>let arr = [{id: 0, children: []},
             {id: 1, children:[
               {id: 2, children: []},
               {id: 3, children: [
                 {id: 4, children: []} 
               ]}
             ]}
           ];
  </code></pre>
  
  <p>I need to count depth level for each object. In all objects I have a parentId property too.</p>
  
  <p>Result should be:</p>
  
  <pre><code>let arr = [{id: 0, depth: 0, children: []},
             {id: 1, depth: 0, children:[
               {id: 2, depth: 1, children: []},
               {id: 3, depth: 1, children: [
                 {id: 4, depth: 2, children: []} 
               ]}
             ]}
           ];
  </code></pre>
  
  <p>I have an array of all the objects in a flat structure too.</p>
  
  <p>Solutions?</p>