title: Remove duplicates from NESTED array of objects
body: <p>I have an array of objects like below, which inside of it has another array of objects which has duplicate <strong>verticalName</strong> values that need to be removed in order to be displayed on the page.</p>
  <pre><code> &quot;landingPages&quot;: [
          {
            &quot;programmes&quot;: [
              {
                &quot;progName&quot;: &quot;Programme 1&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;8&quot;,
                    &quot;verticalName&quot;: &quot;Law and Criminology&quot;
                  }
                ]
              }
            ]
          },
          {
            &quot;programmes&quot;: [
              {
                &quot;progName&quot;: &quot;Programme 2&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;1&quot;,
                    &quot;verticalName&quot;: &quot;Psychology and Sociology&quot;
                  }
                ]
              }
            ]
          },
          {
            &quot;programmes&quot;: [
              {
                &quot;progName&quot;: &quot;Programme 3&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;3&quot;,
                    &quot;verticalName&quot;: &quot;Computing and IT&quot;
                  }
                ]
              }
            ]
          },
          {
            &quot;programmes&quot;: [
              {
                &quot;progName&quot;: &quot;Programme 4&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;1&quot;,
                    &quot;verticalName&quot;: &quot;Psychology and Sociology&quot;
                  }
                ]
              },
              {
                &quot;progName&quot;: &quot;Programme 5&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;3&quot;,
                    &quot;verticalName&quot;: &quot;Computing and IT&quot;
                  }
                ]
              },
              {
                &quot;progName&quot;: &quot;Programme 6&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;2&quot;,
                    &quot;verticalName&quot;: &quot;Business and Management&quot;
                  }
                ]
              },
              {
                &quot;progName&quot;: &quot;Programme 7&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;3&quot;,
                    &quot;verticalName&quot;: &quot;Computing and IT&quot;
                  }
                ]
              },
              {
                &quot;progName&quot;: &quot;Programme 8&quot;,
                &quot;verticals&quot;: [
                  {
                    &quot;id&quot;: &quot;3&quot;,
                    &quot;verticalName&quot;: &quot;Computing and IT&quot;
                  }
                ]
              }
            ]
          }
        ]
  </code></pre>
  <p>I have tried couple of solutions, some of the did not work but one did, which I copy/pasted below. I've managed to store all of them inside of one array of objects, it's just that the code to me looks really bad. I am trying to find a cleaner solution to this problem. Here is my solution and I would like to see how does it compare to your solutions maybe, and if you could give me some feedback that would be amazing.</p>
  <pre><code>    let known = {}
      let noduplicates = programmes.map((subarray) =&gt; {
          const newarrays = []
          subarray.verticals.forEach((item) =&gt; {
              if (
                  !known.hasOwnProperty(item.verticalName) &amp;&amp;
                  (known[item.verticalName] = true)
              ) {
                  newararys.push(item)
              } else {
                  console.log('test')
              }
          })
          console.log(newarrays)
          return newarrays
      })
      const fil = filtered.filter((item) =&gt; item.length)
      const singleArr = fil.reduce((a, b) =&gt; a.concat(b), [])
      console.log(singleArr)
  </code></pre>
  <p>What I am trying to get is something like this, basically, just all the objects that were found inside of <strong>verticals</strong> array, but - without duplicates:</p>
  <pre><code>[
     {id: &quot;1&quot;, verticalName: &quot;Psychology and Sociology&quot;}, 
     {id: &quot;3&quot;, verticalName: &quot;Computing and IT&quot;}, 
     {id: &quot;2&quot;, verticalName: &quot;Business and Management&quot;}
  ]
  </code></pre>
  <p>Cheers everyone!</p>