title: why map() function always returns something even if condition statement does not match?_ java script
body: <p>take a look at this example:</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>let my_array = [1,2,4,5,6,7,8]
  
  
  
  test = my_array.map(element=&gt;{
      if(element!==1){
          return element
      }
  })
  
  
  console.log(test)</code></pre>
  </div>
  </div>
  </p>
  <p>why map() function always return something if the statement does not match?</p>
  <p>I know map function iterate over the indexes of array. but why returns null? we said return only if the statement is true.</p>
  <p>how we can avoid null in return of map()?</p>
  <p>update: I needed combination of map() and filter():</p>
  <pre><code>let my_array = [1, 2, 4, 5, 6, 7, 8]
  test = my_array
    .filter(element =&gt; element !== 1)
    .map(element =&gt; element * 2);
  
  console.log(test)
  </code></pre>