title: returning data efficiently in loop with java script
body: <p>I recently fall in a loop pit when i tried to return data from a multi loop statement.</p>
  
  <p>I am creating profile filtering system which after fetch people. It will filter the friends of the user.</p>
  
  <pre><code> class UserFriend {
  
     analyseUserFriends(people, userfriends){
      people.forEach(person =&gt; {
          this.userfriends.forEach(friend =&gt; {
              if(person._id.toString() == friend._id.toString()){
                  person.relationship = 0
              }else{
                 person.relationship = 1;
               }
              return friend;//After loging friend the object of relationship is part of the member
          });
           return person;//After loging person the object of relationship is not part of the member
       });
    }
  }
  </code></pre>
  
  <p>The data are from Mongo and it similar to this</p>
  
  <pre><code>     userfriends:[ 
      {friend: mongoId},
      {friend: mongoId},
      {friend: mongoId},
      {friend: mongoId},
  ];
  people: [
      {_id: mongoId}, 
      {_id: mongoId}, 
      {_id: mongoId}, 
      {_id: mongoId},
      {_id: mongoId}, 
      {_id: mongoId}, 
      {_id: mongoId}, 
      {_id: mongoId}
  ];
  </code></pre>
  
  <p>Thanks.</p>