title: Use variables only if exists into a array filter express
body: <p>I have an endpoint in express with some variables, each of them can be there or not, depending of the variables i have to do a filter function over a array and applie the rules coming fron the req.body.</p>
  <p>Is there any way to apply if conditions inside the return of an filter function?</p>
  <p>The code is this:</p>
  <pre><code>test.getModelsFile = async (req, res) =&gt; {
   let data = json;
   const SubModel = req.body.SubModel;
   const Years = req.body.Years;
   const Engine = req.body.Years;
   const Make = req.body.Make;
  
    let result = data.filter((x) =&gt; {
     return x.Make == Make(Years) &amp;&amp; x.Years == Years &amp;&amp; x.Engine == Engine &amp;&amp; x.SubModel == SubModel;
    });
  result = await deleteRepeatedFromArray(result, &quot;Model&quot;);
  res.send(result);
  };
  </code></pre>
  <p>This will only work if those variables came from the req.body, if they are not it will return an error, what can i do?</p>