title: How to traverse nested array upwards from current record?
body: <p>I want to traverse array from my current node to last parent node in following way :</p>
  
  <p><a href="https://i.stack.imgur.com/nfHqY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nfHqY.png" alt="enter image description here"></a></p>
  
  <p>Rules:</p>
  
  <ul>
  <li><p>Node-1 (take str from text array property from here whose str is not null and push it to currentText in parent array property)</p></li>
  <li><p>Node-1-1(take str from text array property from here whose str is not null and push it to currentText in parent array property)</p></li>
  </ul>
  
  <p>Now what I am trying to do is for Node-1-1-1 and for currentText of Node-1-1-1 I want to traverse like this :</p>
  
  <p>Node-1-1-1  ===>   Node-1-1  ====> Node-1:</p>
  
  <pre><code>1)  Node-1-1-1  ===&gt;   Node-1-1
  
      If(Node-1-1.text[0].str !=null)
         currentText.parent.push(Node-1-1.text[0].str);
      else if(Node-1-1.text[1].str!=null)
        currentText.parent.push(Node-1-1.text[1].str);
      else 
         //do nothing
  
  2) Node-1-1  ====&gt; Node-1
  
    If(Node-1.text[0].str !=null)
         currentText.parent.push(Node-1.text[0].str);
      else if(Node-1.text[1].str!=null)
        currentText.parent.push(Node-1.text[1].str);
      else 
         //do nothing
  </code></pre>
  
  <p>So at the end for Node-1-1-1 and for currentText of Node-1-1-1,i should have output like below :</p>
  
  <pre><code>var currentText = 
                {
                   "str" : "This is my first Node-1-1-1 string",
                   "parent":[
                               {
                                 "str" : ""This is my first Node-1 string"
                               },
                               {
                                 "str" : ""This is my first Node-1-1 string"
                               }
                            ]
                }
  </code></pre>
  
  <p><strong>Note :</strong> <code>currentNode</code> variable will have different node Object based on node selection.So if user selected node Node-1-1-1 then currentNode will have Node-1-1-1 object and if user selected Node-1-1 currentNode will have Node-1-1 object etc.</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>var records = [
    {
      "name": "Node-1",
      "isParent": true,
      "text" : [
         {
             "str" : "This is my first Node-1 string",
             "parent":[]
         },
         {
            "str" : "This is my second Node-1 string",
             "parent":[]
         }],
       "nodes": [
        {
          "name": "Node-1-1",
          "isParent": false,
           "text" : [
             {
               "str" : "This is my first Node-1-1 string",
               "parent":[]
             },
             {
               "str" : "This is my second Node-1-1 string",
               "parent":[]
             }],
             "nodes": [
             {
              "name": "Node-1-1-1",
              "isParent": false,
              "text" : [
              {
                "str" : "This is my first Node-1-1-1 string",
                "parent":[]
              },
              {
                "str" : "This is my second Node-1-1-1 string",
                "parent":[]
              }],
              "nodes": []
            }
          ]
        }
      ]
    }
  ]
  
  var currentNode={
              "name": "Node-1-1-1",
              "isParent": false,
              "text" : [
              {
                "str" : "This is my first Node-1-1-1 string",
                "parent":[]
              },
              {
                "str" : "This is my second Node-1-1-1 string",
                "parent":[]
              }],
              "nodes": []
            }
  var currentText = 
                {
                   "str" : "This is my first Node-1-1-1 string",
                   "parent":[]
                }
  
  console.log(records);</code></pre>
  </div>
  </div>
  </p>