title: How to get parent path all the way to the last child in javascript
body: <p>I am having a difficult time trying to get the path from the parent down to the child. </p>
  
  <p>The below "fullPath" is what i am trying to achieve. Get the parent path followed by the children path. </p>
  
  <pre><code>[{
      "name": "menu1",
      "path": "/path1",
      "id": 1,
      "parentId": 0,
      "item": [{
          "name": "subMenu1",
          "path": "/itemPath1",
          "parentId": 1,
          "id": 3,
          "fullpath": "/path1/itemPath1"
      }, {
          "name": "subMenu2",
          "path": "/itemPath2",
          "parentId": 1,
          "id": 4,
          "fullpath": "/path1/itemPath2"
      }]
  
  }, {
      "name": "menu2",
      "path": "/path2",
      "id": 2,
      "parentId": 0,
      "item": [{
          "name": "subMenu2",
          "path": "/itemPath2",
          "parentId": 2,
          "id": 5,
          "fullpath": "/path2/itemPath2"
      }]
  
  }]
  </code></pre>
  
  <p>The javascript function used to create the above json.</p>
  
  <pre><code>var getList = function(list) {
                  var result = {items: []},length = list.length;
  
                  var tmpStore = {}
                  var i, item, id, pId;
  
                  for (i = 0; i &lt; length; ++i) {
                      item = list[i];
                      id = item.id;
                      tmpStore[id] = item;
                      pId = parseInt(item.parentId, 10);
  
                      if (pId === 0) {
                          result.items.push(item);
                      } else {
  
                          if (typeof tmpStore[pId].items === 'undefined') {
                              tmpStore[pId].items = [];
                          }
                          tmpStore[pId].items.push(item);
                      }
  
  
                  }
  
                  return result;
              };
  
              var output = getList(list1);
              var sideDetailsInfo = output.items;
              console.log(sideDetailsInfo)
  </code></pre>
  
  <p>//The above function created by fuyushimoya. </p>
  
  <pre><code>var list1 variable contains the below.
  
  var list1 = [{
          "name": "menu1",
          "id": 1,
          "parentid": 0,
          "path": "/path1"
      }, {
          "name": "menu2",
          "id": 2,
          "parentid": 0,
          "path": "/path2"
      }, {
          "name": "subMenu1",
          "id": 3,
          "parentid": 1,
          "path": "/itemPath1"
      }, {
          "name": "subMenu2",
          "id": 4,
          "parentid": 1,
          "path": "/itemPath2"
      }, {
          "name": "subMenu2",
          "id": 5,
          "parentid": 2,
          "path": "/itemPath2"
      }]
  </code></pre>
  
  <p>Your help is appreciated and any advice would be great. </p>