title: How to map items without undefined value in javascript with Array.prototype.map and without Array.prototype.filter()
body: <p>How to map items without undefined value in javascript with Array.prototype.map and without Array.prototype.filter()</p>
  
  <p>Code:</p>
  
  <pre><code>var testArray = [
    {
      name: "toto",
      totoNumber: "1",
    },
    {
      name: "tata",
      totoNumber: "2",
    },
    {
      mame: "error",
    },
  ]
  
  var listOfToto = testArray.map(x =&gt; x.totoNumber);
  var listOfToto2 = testArray.map(x =&gt; x.totoNumber ? x.totoNumber : undefined);
  var listOfToto3 = testArray.filter(x =&gt; x.totoNumber).map(x =&gt; x.totoNumber);
  
  console.log(listOfToto);  
  console.log(listOfToto2);  
  console.log(listOfToto3);  
  </code></pre>
  
  <p>Values:</p>
  
  <blockquote>
    <p>Array ["1", "2", undefined]<br>
    Array ["1", "2", undefined]<br>
    Array ["1", "2"]</p>
  </blockquote>
  
  <p>I want to get the last array (["1", "2"]) without using <strong>Array.prototype.filter()</strong><br>
  (maybe with something else than <strong>Array.prototype.map()</strong>)</p>
  
  <p>Other source:<br>
  <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map</a><br>
  <a href="https://stackoverflow.com/questions/16037049/why-does-javascript-map-function-return-undefined">Why does javascript map function return undefined?</a><br>
  <a href="https://codewithhugo.com/avoiding-falsy-values-in-javascript-arrays/" rel="nofollow noreferrer">https://codewithhugo.com/avoiding-falsy-values-in-javascript-arrays/</a>  </p>