title: Remove Object from Json Object
body: <p>I was looking for solutions from Google and from this site. But I did not find the right answer for me. I have a json object:</p>
  
  <pre><code>$scope.jsonObject = {
      "Card":{
            "type":"menu",
            "options":["option1","option2"],
            "name":"With card",
            "next":{
                 "operations":{
                     "type":"menu",
                     "options":["option1","option2"],
                     "name":"Card Operations",
                     "next":{ 
                          "balance":{ 
                             "type":"transaction",
                             "options":["option1","option2"],
                             "name":"Get Balance",
                             "next":null           
                           },
                           "history":{ 
                             "type":"transaction",
                             "options":["option1","option2"],
                             "name":"History Card",
                             "next":null           
                           }
                     }
  
                }  
          }
     }
  }
  </code></pre>
  
  <p>This is a template menu, From this menu I need create new menu with angular foreach:</p>
  
  <pre><code>$scope.sortMenu = {};
  function sortObject(menu){
    angular.foreach(menu, function(key,value){
      if(key == "card"){
         $scope.sortMenu = menu;
      } 
      if(key == "history"){
         // I need delete object "history" from $scope.sortMenu    
      }
      sortObject(value.next);
    });
  }
  sortObject($scope.jsonObject);
  </code></pre>
  
  <h2>How to write for delete "history" object from new menu?</h2>
  
  <p>Thanks, for all answers. Now, I change the question a bit. This is the $scope.jsonObject in the browser:</p>
  
  <p><a href="https://i.stack.imgur.com/RA8Lb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RA8Lb.jpg" alt="enter image description here"></a></p>
  
  <p>This is a menu creator:</p>
  
  <pre><code>function showDefaultMenu(menu,iterator){
              angular.forEach(menu, function(value, key){
                  console.log(key);
                  $('#myTree').append(
                      "&lt;div class='col-md-12 col-xs-12'&gt;" +
                      "&lt;input type='checkbox' id='"+key+"' value='"+key+"' style='position: inherit;margin-left:"+iterator+"px'&gt;"+key+
                      "&lt;/div&gt;"
                  );
                  if(value.next !== undefined){
                      showDefaultMenu(value.next,iterator+20);
                  }
              });
          }
          showDefaultMenu($scope.jsonObject,20);
  </code></pre>
  
  <p>This is a code in html:</p>
  
  <pre><code>&lt;div id="myTree" class="col-md-12 col-xs-12" style="margin-top: 50px;border:1px solid black;"&gt;
  &lt;/div&gt;
  &lt;div class="col-md-12 col-xs-12" style="margin-top: 10px;" &gt;
       &lt;input type="button" ng-click="constructNewMenu()" class="button btn-xs btn-info" value="Create Menu" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is a <code>constructNewMenu()</code> used instead of <code>sortObject()</code>:</p>
  
  <pre><code>function constructNewMenu(){
       assistantConstructMenu($scope.jsonObject);
  }
  
  function assistantConstructMenu(menu){
      angular.forEach(menu, function(value, key){
          if ($('#' + key).is(':checked')) {
              if (key === "card") {
                  $scope.sortMenu.push(menu);
              }
          }else{
             // I need delete object "no checked" from $scope.sortMenu
          }
          if(value.next !== undefined){
              assistantConstructMenu(value.next);
          }
      });
  }
  </code></pre>
  
  <p>How to delete "no checked" menu, not knowing his level in the hierarchy of an object?</p>