title: Reassigning values from multilevel array of objects
body: <p>I have got an array of objects like this:</p>
  
  <pre><code>[
    {
      "pageId": "1",
      "menuPos": "Parent",
      "mainPageId": "1",
      "subMenu": [
        {
          "pageId": "1",
          "menuPos": "Parent and child",
          "mainPageId": "1",
          "subMenu": [
            {
              "pageId": "67",
              "menuPos": "Child",
              "mainPageId": "67"
            },
            {
              "pageId": "68",
              "menuPos": "Child and paren",
              "mainPageId": "68",
              "subMenu": [
                {
                  "pageId": "70",
                  "menuPos": "Child",
                  "mainPageId": "70"
                },
                {
                  "pageId": "69",
                  "menuPos": "Child",
                  "mainPageId": "69"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
  </code></pre>
  
  <p>Thanks to tymeJV from stackoverlow now i know how to iterate trough this array, but i still working on how to reassign values from array to another array. I made a recursive function for this, but in output i still have the same values. Here is the code.</p>
  
  <p>currentData = event.dest.nodesScope.$treeScope.data;</p>
  
  <pre><code>    var outputData = [];
  
      function iterateMenus(menu) {
  
          if(menu.length &gt; 0) {
          outputData = [];
          for (var i = 0; i &lt; menu.length; i++) {
              console.log(menu[i].pageId+" "+menu[i].menuPos);
              outputData[i] = {
                  menuPos: menu[i].menuPos,
                  pageId: menu[i].pageId,
                  subMenu: [ iterateMenus(menu[i].subMenu) ]
                  }
              }
          }
          return outputData;
      }
  
      var output = iterateMenus(currentData);
  </code></pre>
  
  <p>In output a i want to display only pageId, menuPos and subMenu if exists. I also want to add parentId if it is possible( i am sure it is )</p>