title: How to return a value from .filter instead of the element
body: <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>function firstDuplicate(a) {
    const duplicates = a.filter((el,idx) =&gt; {
      let myVar = a.indexOf(el,idx+1);
      console.log(myVar); // returns 4
      if (myVar &gt;= 0) return myVar; // duplicates becomes [1] instead of [4]
    });
    console.log('duplicates are',duplicates);
  }
  const myArr = [1,2,3,4,1];</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm trying to return a value from filter instead of the array element. How do I do this? Ultimately I want to get all the duplicates in an array for a coding challenge.</p>