title: javascript, get indices of given value in array
body: <p>This JavaScript code tries to get the indices of a given value 5 in a new array. Any idea how to do it in an elegant way. I cold use for loop but I was hoping to use map or reduce. thx.  </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>console.log( [1, 2, 3, 5, 6, 5].map((y, i) =&gt; {
    if (y === 5) return i
  }))
  // gives --&gt; [undefined, undefined, undefined, 3, undefined, 5]
  // expected [3,5]</code></pre>
  </div>
  </div>
  </p>