title: Manipulating javascript object with underscore
body: <p>I have a Javascript object with a format like below</p>
  
  <pre><code>"items":
           {
           "Groups":[
              {
                 "title":"group 1",
                 "SubGroups":[
                    {
                       "title":"sub1",
                       "id" : "1",
                       "items":[
                          {
                             "title":"Ajax request 1",
                          },
                          {
                             "title":"Ajax request 2",
                          }
                       ]
                    },
                      {
                       "title":"sub2",
                       "id" : "2",
                       "items":[
                          {
                             "title":"Ajax request 3",
                          },
                          {
                             "title":"Ajax request 4",
                          }
                       ]
                    }
                 ]
              }
           ]
  </code></pre>
  
  <p>There are n 'Groups', n 'subGroups' and n 'items'.</p>
  
  <p>What I want to do firstly is get all the items from a particular group based on id. This is achieved using:</p>
  
  <pre><code>_.each(items.Groups, function(o) {
       result = _.where(o.SubGroups, {
      'id': '1'
    });
  });
  </code></pre>
  
  <p>which returns</p>
  
  <pre><code>"items":[{"title":"Ajax request 1",},{"title":"Ajax request 2",}]
  </code></pre>
  
  <p>Then I want to get the rest of the data, excluding the items and parent group I have just retrieved.</p>
  
  <p>I tried this:</p>
  
  <pre><code>_.each(items.Groups, function(o) {
          arr = _.without(o.SubGroups, _.findWhere(o.SubGroups, {id: '2'}));
    });
  </code></pre>
  
  <p>But this only returns me the items like this:</p>
  
  <pre><code>{
   "title":"sub2",
   "id" : "2",
   "items":[{"title":"Ajax request 3"},{"title":"Ajax request 4",}]
  }
  </code></pre>
  
  <p>whereas what I need is this:</p>
  
  <pre><code> "items":
               {
               "Groups":[
                  {
                     "title":"group 1",
                     "SubGroups":[
                          {
                           "title":"sub2",
                           "id" : "2",
                           "items":[
                              {
                                 "title":"Ajax request 3",
                              },
                              {
                                 "title":"Ajax request 4",
                              }
                           ]
                        }
                     ]
                  }
               ]
  </code></pre>