title: How to check all entries in an array of objects for two equal properties
body: <p>I have an array of objects which I want to reduce and add a property. If two key/values are the same (name &amp; size) the entries should be combined like the following:</p>
  <p>The original array looks like this:</p>
  <pre><code>[
    {
      id: 1
      name: &quot;foo&quot;,
      size: 4998,
      relatedId: 17,
      link: &quot;https://www.google.com/&quot;
    },
    {
      id: 2
      name: &quot;foo&quot;,
      size: 4998,
      relatedId: 21,
      link: &quot;https://www.google2.com/&quot;
    },
    {
      id: 3
      name: &quot;bar&quot;,
      size: 381,
      relatedId: 35,
      link: &quot;https://www.google3.com/&quot;
    },
    {
      id: 4
      name: &quot;bar&quot;,
      size: 381,
      relatedId: 41,
      link: &quot;https://www.google4.com/&quot;
    },
    {
      id: 5
      name: &quot;baz&quot;,
      size: 666,
      relatedId: 50,
      link: &quot;https://www.google5.com/&quot;
    },
  ]
  </code></pre>
  <p>And I want to generate the following output:</p>
  <pre><code>[
    {
      id: 1
      name: &quot;foo&quot;,
      size: 4998,
      relatedId: 17,
      link: &quot;https://www.google.com/&quot;,
      relations: [
        {
          id:1,
          relatedId: 17
        },
        {
          id:2,
          relatedId: 21
        }
      ]
    },
    {
      id: 3
      name: &quot;bar&quot;,
      size: 381,
      relatedId: 35,
      relations: [
        {
          id: 3,
          relatedId: 35
        },
        {
          id: 4,
          relatedId: 41
        }
      ]
    },
    {
      id: 5
      name: &quot;baz&quot;,
      size: 666,
      relatedId: 50,
      relations: [
        {
          id: 5,
          relatedId: 50
        }
      ]
    }
  ]
  </code></pre>
  <p>So the new property <em>relations</em> with the <em>id</em> and the <em>relatedId</em> should be added to the objects and if 2 or more objects have the same <em>name</em> and <em>size</em> the entries from the second on should be removed and the <em>id</em> and <em>relatedId</em> should be pushed to the <em>relations</em>.</p>
  <p>I tried this but it doesn't work yet:</p>
  <pre><code>mergeDuplicates (fileArray) {
      for (let i = 0; i &lt; fileArray.length; i++) {
          fileArray[i].relations = []
          fileArray[i].relations .push({
              id: fileArray[i].id,
              relatedId: fileArray[i].relatedId,
          })
          for (let j = 1; j &lt; fileArray.length; j++) {
              if (fileArray[i].name=== fileArray[j].name &amp;&amp; fileArray[i].size === fileArray[j].size) {
                  fileArray[i].relations .push({
                      id: fileArray[j].id,
                      relatedId: fileArray[j].relatedId,
                  })
                  fileArray.splice(j, 1)
              }
          }
      }
  
      return fileArray;
  }
  </code></pre>