title: Filtering with dynamic criteria to exclude some values in javascript
body: <p>I have a data array of strings:</p>
  
  <pre><code>0:"dbname_default_2018-10-26"
  1:"dbname_default_2018-10-27"
  2:"dbname_default_2018-10-28"
  3:"dbname_default_2018-10-30"
  4:"dbname_default_2018-10-31"
  5:"dbname_default_2018-11-01"
  6:"dbname_default_2018-11-03"
  7:"dbname_default_2018-11-04"
  8:"dbname_default_2018-11-06"
  9:"dbname_default_2018-11-07"
  10:"dbname_default_2018-11-08"
  </code></pre>
  
  <p>…and another array of criteria, which is dynamically created with <code>formatDate</code>:</p>
  
  <pre><code>0:"2018-11-06"
  1:"2018-11-07"
  </code></pre>
  
  <p>I would like to splice items where the name includes the criteria. The goal is to delete database names depending on seniority days. So if seniority is 2, it should only keep items with date is today-2days and older.</p>
  
  <p>Here's my program:</p>
  
  <pre><code>async function selectDdToDelete(dbArray, seniority) {
      let datesToKeep: string[] = [];
      let dbTokeep;
      for (let i = seniority; i &gt;= 0; i--) {
          datesToKeep.push(
              `${formatDate(i).year}-${formatDate(i).month}-${formatDate(i).day}`
          );
      }
      dbTokeep = dbArray.filter(elm =&gt; {
          let exists = false;
          for (let i = 0; i &lt; datesToKeep.length; i++) {
              if (elm.includes(datesToKeep[i])) {
                  exists = true;
              }
          }
          if (!exists) {
              return elm;
          }
      });
  
      return dbTokeep;
  }
  </code></pre>
  
  <p>I'm getting firstly an array of criteria with <code>formatDate()</code> which sends me an object <code>{year:2018,month:"11",day:"06"}</code>, for example if <code>i==1</code> ( today date -i). </p>
  
  <p>Then I'm filtering on the data array. Inside it, I loop the array criteria and with an intermediate variable, I decide wether I return the element or not.</p>
  
  <p>Then I send the new filtered array.</p>
  
  <p>My problem is that actually I get the same array in entry that at the end.</p>
  
  <p>What I expect to get is:</p>
  
  <pre><code>0:"dbname_default_2018-10-26"
  1:"dbname_default_2018-10-27"
  2:"dbname_default_2018-10-28"
  3:"dbname_default_2018-10-30"
  4:"dbname_default_2018-10-31"
  5:"dbname_default_2018-11-01"
  6:"dbname_default_2018-11-03"
  7:"dbname_default_2018-11-04"
  8:"dbname_default_2018-11-08"
  </code></pre>