title: JavaScript: Find all parents for element in tree recursive
body: <p>I have a tree somthing like this</p>
  
  <pre><code>var datas = {
      'tree': [
          {
              'name': 'name1',
              'tree': [
                  {'name': 'name2'},
                  {'name': 'name3'},
                  {
                      'name': 'name4',
                      'tree': [
                          {'name': 'name5'},
                          {'name': 'name6'}
                      ]
                  },
                  {'name': 'name7'}
              ]
          },
          {
              'name': 'name8',
              'tree': [
                  {'name': 'name9'}
              ]
          }
      ]
  }
  </code></pre>
  
  <p>I want to find all the parents of the specifig id</p>
  
  <p>for example in the tree demo, if I look for 'name5' I want to find "name1,name4,name5"</p>
  
  <p>I wrote this code but the results wrong and I got the ids of other elements and not the parents only</p>
  
  <p>This is my code</p>
  
  <pre><code> keys: string[];
    pathFound: boolean = false;
   getLevel(event: iEventBase, id: string, path: string[]): void {
      if (this.pathFound) return;
      event.content.forEach((key) =&gt; {
        if (key.id == id) {
          if(!path){
            path =  [];;
          }
          path.push(key.id);
          this.keys = path;
          this.pathFound = true;
          return;
        }
        if (key.type === "page") {
          if(!path){
            path = [];
          }
          path.push(key.id);
          this.getLevel(key, id, path);
        }
      })
    }
  }
  this.getLevel(state.mainEvent.content.page, event.id, null);
  </code></pre>