title: Understanding map and join to create unique array
body: <p>The following code is from <a href="https://stackoverflow.com/questions/38613654/javascript-find-unique-objects-in-array-based-on-multiple-properties">this</a> SO post. The code works as expected but I am unable to understand how the code is working. The accepted answer for this post is very similar but I was unable to understand that as well.</p>
  
  <pre><code>const array = [
   { class: "second", fare: "a" }, 
   { class: "second", fare: "b" }, 
   { class: "first", fare: "a" }, 
   { class: "first", fare: "a" }, 
   { class: "second", fare: "a" }, 
   { class: "first", fare: "c" }
  ];
  
  console.log(unique(array, ['class', 'fare']));
  
  function unique(arr, keyProps) {
   const kvArray = arr.map(entry =&gt; {
    const key = keyProps.map(k =&gt; entry[k]).join('|');
    return [key, entry];
   });
   const map = new Map(kvArray);
   return Array.from(map.values());
  }
  </code></pre>
  
  <p>when I console <code>entry[k]</code> I see all the values but after joining, the see only the unique values. </p>
  
  <p>Can someone please help me understand this.</p>