Javascript Recursion: How to the instance of parent access of the child node
<p>i'm trying to build the logic to get access to the all parent nodes of the child I've currently access to via recursion,but not able to do so. here's what I've done so far:</p>

<p>Here's my array:</p>

<pre><code>var results = [{
  "key": 1,
  "name": "A",
  "child": [{
    "key": 2,
    "name": "A1",
    "child": [{
      "key": 1473591350189,
      "name": "A11"
    }]
  }, {
    "key": 10,
    "name": "A2",
    "child": []
  }]
}, {
  "key": 66,
  "name": "B",
  "child": [{
    "key": 67,
    "name": "B1",
    "child": [{
      "key": 68,
      "name": "B11",
      "child": [{
        "key": 69,
        "name": "B111",
        "child": []
      }]
    }]
  }]
}];
</code></pre>

<p>Now my logic is for iteration:</p>

<pre><code>function recursionFn(results, parentNode) {
  for (var i = 0; i &lt; results.length; i++) {
    var _node = results[i];
    if (_node.child.length &gt; 0) {
      console.log('Name: ' + _node.name + ' First Childs: ' + _node.child.length);
      if (parentNode)
        console.log('ParentNode: ' + parentNode.name);
    }
    if (_node.child.length &gt; 0)
      recursionFn(_node.child, _node);
    if (_node.child.length == 0) {
      console.log('Name: ' + _node.name + ' Second Childs: ' + _node.child.length);
      if (parentNode)
        console.log('ParentNode: ' + parentNode.name);
    }
  }
}
</code></pre>

<p>Here I'm getting the immediate parent of the current child I'm in but how do I get access to all the parents of that child. For instance, if the relationship is:
<strong>A -> A1 -> A11</strong>
Then how do I get access to all parents of <strong>A11</strong>? Thanks in advance!!</p>