title: accessing the parent object from the child object property in javascript
body: <p>My problem . I have an object like this:</p>
  
  <pre><code>t.mainobject = {
      prop1: "",
      prop2: "",
      id: "1",
      prop3: [
          child1: {
              id: "111"
          },
          child2: {
              id: "112"
          }
      ]
  };
  </code></pre>
  
  <p>only child1/child2 is visible to me whereas I donot know its parent object . I tried using underscore but have not found any method which can provide me the parent object . </p>
  
  <p>thanks in advance for any advice/suggestion.</p>
  
  <p>edit1:<br>
     all my child objects were created from multiple object so it end up as a flatten object.</p>
  
  <p>like:</p>
  
  <pre><code>t.mainobject = {
      prop1: "",
      prop2: "",
      id: "1",
      prop3: [
          child1: {
              id: "111"
          },
          child2: {
              id: "112"
          }
      ]
  };
  
  
  t.mainobject1 = {
      prop1: "",
      prop2: "",
      id: "2",
      prop3: [
          child1: {
              id: "211"
          },
          child2: {
              id: "212"
          }
      ]
  };
  
  t.mainobject3 = {
      prop1: "",
      prop2: "",
      id: "1",
      prop3: [
          child1: {
              id: "311"
          },
          child2: {
              id: "312"
          }
      ]
  };
  </code></pre>
  
  <p>Now I ended up with an array with :</p>
  
  <pre><code>[{id:"111"},{id:"112"}, {id:"211"},{id:"212"}, {id:"311"},{id:"312"}]
  </code></pre>
  
  <p>Now how can I able to get the parent object containing the child object using the id .</p>
  
  <p>edit 2:</p>
  
  <p>my solution :</p>
  
  <pre><code>var parent = _.filter(allParent, function(r){
              for(var i=0; i&lt;r.posts.length; i++){
                  if(r.posts[i].id === allChildPosts[index].id){
                      return r.id;
                  }
              }
          });
  </code></pre>
  
  <p>it return me the parent object and now I can easily access any property.</p>