title: Trying to filter an array of objects based on several fields in JS
body: <p>First of all, my apologies if my question is too obvious but I my knowledge is limited and I don't get how to achieve what I am trying. I have a JSON file as source of the data (songs) and I am trying to filter that data based on several fields (level, name, artist, etc.).</p>
  <p>Example of some data from the JSON:</p>
  <pre><code>[
    {&quot;artist&quot;: &quot;Black&quot;,
      &quot;categories&quot;: &quot;Arreglos&quot;,
      &quot;date&quot;: 1639127185000,
      &quot;level&quot;: &quot;Fácil&quot;,
      &quot;musicStyle&quot;: &quot;Pop/Rock&quot;,
      &quot;name&quot;: &quot;Wonderful Life&quot;,
      &quot;practice&quot;: &quot;n/a&quot;,
      &quot;preloadID&quot;: &quot;Wonderful_Life&quot;,
      &quot;subtitle&quot;: &quot;Fácil&quot;,
    },
  {&quot;artist&quot;: &quot;&quot;,
      &quot;categories&quot;: &quot;Arreglos&quot;,
      &quot;date&quot;: 1587948049309,
      &quot;image&quot;: &quot;./images/arreglos/a_million_dreams.jpeg&quot;,
      &quot;level&quot;: &quot;Fácil&quot;,
      &quot;musicStyle&quot;: &quot;Film/TV&quot;,
      &quot;name&quot;: &quot;A million dreams&quot;,
      &quot;preloadID&quot;: &quot;AMillionDreams_Facil&quot;,
      &quot;subtitle&quot;: &quot;Fácil&quot;,
    },
  {&quot;artist&quot;: &quot;&quot;,
      &quot;categories&quot;: &quot;Arreglos&quot;,
      &quot;date&quot;: 1587948046688,
      &quot;image&quot;: &quot;./images/arreglos/a_million_dreams.jpeg&quot;,
      &quot;level&quot;: &quot;Principiante&quot;,
      &quot;musicStyle&quot;: &quot;Film/TV&quot;,
      &quot;name&quot;: &quot;A million dreams&quot;,
      &quot;preloadID&quot;: &quot;AMillionDreams_Principiante&quot;,
      &quot;subtitle&quot;: &quot;Principiante&quot;,
    },
  {&quot;artist&quot;: &quot;Vanessa Carlton&quot;,
      &quot;categories&quot;: &quot;Arreglos&quot;,
      &quot;date&quot;: 1602939064030,
      &quot;level&quot;: &quot;Fácil&quot;,
      &quot;musicStyle&quot;: &quot;Pop/Rock&quot;,
      &quot;name&quot;: &quot;A thousand miles&quot;,
      &quot;preloadID&quot;: &quot;AThousandMiles_Facil&quot;,
      &quot;subtitle&quot;: &quot;Fácil&quot;,
    },
  {&quot;artist&quot;: &quot;Vanessa Carlton&quot;,
      &quot;categories&quot;: &quot;Arreglos&quot;,
      &quot;date&quot;: 1602939064033,
      &quot;level&quot;: &quot;Muy fácil&quot;,
      &quot;musicStyle&quot;: &quot;Pop/Rock&quot;,
      &quot;name&quot;: &quot;A thousand miles&quot;,
      &quot;preloadID&quot;: &quot;AThousandMiles_MuyFacil&quot;,
      &quot;subtitle&quot;: &quot;Muy fácil&quot;,
      &quot;tonality&quot;: &quot;&quot;
    },
  ]
  </code></pre>
  <p>And this is the script I have to try to filter the data.</p>
  <pre><code>let filteredItems = [];
  let filterLevel=this.context.appActions.dataSlots['ds_LevelFilter'];
  let filterStr=this.context.appActions.dataSlots['ds_SearchFilter'];
  filterStr=filterStr.toLowerCase();
        
        items.forEach(item =&gt; {
          if (item[&quot;artist&quot;].toLowerCase().includes(filterStr) || item[&quot;name&quot;].toLowerCase().includes(filterStr) ) {
            filteredItems.push(item);
            }
        });
        
        items.forEach(item =&gt; {
          if (item[&quot;level&quot;] == filterLevel) {
            filteredItems.push(item);
          }
        });
        
        items = filteredItems.sort((a, b) =&gt; {
                return new Date(b.date) - new Date(a.date);
              }).slice(0,this.context.appActions.dataSlots['ds_limitQuery']);
  
  return items;
  </code></pre>
  <p>For filterStr, I have a text field where the user would write a search and if that is included in name or artist, it should return the resulted documents.</p>
  <p>In filterLevel I have a picker with several values (Easy, Medium, etc. in Spanish) and it should be equal to the field &quot;level&quot; from the data.</p>
  <p>I am not sure if the code shows what I am trying but if I use just the first if block (name and artist) it works perfectly. But if I add the second, it gives me an error of duplicated keys (it is a React project). I am guessing the script is not correct.</p>