title: Javascript find node from tree with recursive function
body: <p>I have <code>JavaScript</code> tree data like this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const tree = {
      children:[
          {id: 10, children: [{id: 34, children:[]}, {id: 35, children:[]}, {id: 36, children:[]}]},
          {id: 10, 
              children: [
                  {id: 34, children:[
                          {id: 345, children:[]}
                      ]}, 
                  {id: 35, children:[]}, 
                  {id: 36, children:[]}
                  ]
          },
          {id: 11, children: [{id: 30, children:[]}, {id: 33, children:[]}, {id: 3109, children:[]}]}
          ],
      id: 45
  }
  
  const getByID = (tree, id) =&gt; {
   let result = null
          if (id === tree.id) {
              return tree
          } else {
              if(tree.children){
                  tree.children.forEach( node=&gt; {
                      result = getByID(node, id)
                  })
              }
              return result
          }
  }
  
  const find345 = getByID(tree, 345)
  console.log(find345)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I was try to find item by its id from this tree. im using recursive function to iterate the tree and its children, but it wont find the item as i expected.</p>
  
  <p>its always return null. expected to return <code>{id: 345, children:[]}</code></p>