title: Filter array based on attributes in javascript/ react
body: <p>Hi I need to filter the companies (array) that have same addresses and create an array like: </p>
  
  <pre><code> [{address:uniqueaddress1,organization:[company1,company2]},
    {address:uniqueaddress2,organization:[company3,company4]
    .....]   
  </code></pre>
  
  <p>I am using the following code:</p>
  
  <pre><code> var organizations = [];
   var  dataPoints = [];
   for (var i = 0; i &lt; companies.length; i++) {
    for (var j = 0; j &lt; companies.length; j++) {
       if (i === j) continue;
       if (companies[j].address === companies[i].address) {
          organizations.push(companies[j]);            
          companies[j].added = true;  //To mark it is added
      }
      dataPoints.push({address:companies[j].address, organizations: companies[j]});
     }   
   }
  </code></pre>
  
  <p>Original array:</p>
  
  <pre><code>  0:Object
    added:true
    address:"sample address 1"
    id:258
    latitude:90.90227
    longitude:12.538208
    name:"Company name 1"
    postalCode:"90450"
  </code></pre>