title: How to filter out distinct array value in javascript
body: <p>I'm trying to filter an array of json objects by unique value.</p>
  
  <p>My structure is like this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr1 = [{
      "badgeNumber": "111",
      "firstName": "Frank",
      "lastName": "Tank"
    },
    {
      "badgeNumber": "111",
      "firstName": "Frank",
      "lastName": "Tank"
    },
    {
      "badgeNumber": "222",
      "firstName": "Frank",
      "lastName": "Tank"
    }
  ];
  
  var arr2 = [];
  
  for (let line of arr1) {
    arr2.push({
      id: line.badgeNumber,
      text: line.badgeNumber
    });
    arr2.push({
      id: line.firstName,
      text: line.firstName
    });
    arr2.push({
      id: line.lastName,
      text: line.lastName
    });
  }
  
  console.log(arr2);</code></pre>
  </div>
  </div>
  </p>
  
  <p>desired output:</p>
  
  <pre><code>[
  0{id: "111", text: "111"}
  1{id: "Frank", text: "Frank"}
  2{id: "Tank", text: "Tank"}
  3{id: "Frank", text: "Frank"}
  4{id: "Tank", text: "Tank"}
  5{id: "222", text: "222"}
  6{id: "Frank", text: "Frank"}
  7{id: "Tank", text: "Tank"}
  ]
  </code></pre>
  
  <p>I've tried this; which is close but it filters out all the ids.  I only care about id with value badgeNumber</p>
  
  <pre><code>for(let i = 0; i &lt; arr2.length; i++) {
      let item = arr2[i];
      if(itemsObj[item.id]) {
          itemsObj[item.id] = item;
          arr2Filteredpush(item);
      }
  }
  </code></pre>