title: Javascript how to filter an array using forEach() inside filter()
body: <p>I have an array of objects and I'd like to filter it based on the objects property values. I'd like to filter it by different properties, so it needed to be dynamic. For this I have an input field where I type and then filter the array. So, let's say I have these 2 different arrays:</p>
  
  <pre><code>const array_one = [
    {id: 1, code: 'ABC123', name: 'John'},
    {id: 2, code: 'DEF456', name: 'Stew'},
      // ...
  ];
  
  const array_two = [
    {id: 1, value: '012345', company: 'Company 01' },
    {id: 2, value: '678910', company: 'Company 02' },
      // ...
  ];
  </code></pre>
  
  <p>I want a function where I can filter the first array based on the <code>name</code>, also If I want to filter the second array, I want to filter it by the <code>value</code>.</p>
  
  <p>For this, I built this function:</p>
  
  <pre><code>filterArray(array: Array&lt;any&gt;, fields: Array&lt;any&gt;, value: string) {
      value = this.convertString(value);
  
      array = array.filter((item) =&gt; {
          fields.forEach(obj =&gt; {
              if ( item[obj] ) {
                  const _newObj = this.convertString(item[obj]);
                  if ( _newObj.indexOf(value) !== -1 ) {
                      console.log(item);
                      return item;
                  }
              }
          });
      });
  
      return array;
  }
  // convertString() is just another function to replace accents, spaces, etc...
  </code></pre>
  
  <p>Then I call it like this: </p>
  
  <pre><code>filterArray(originalArray, ['name'], valueFromInput);
  
  // or...
  filterArray(originalArray, ['value'], valueFromInput);
  
  // or even...
  filterArray(originalArray, ['value', 'company'], valueFromInput);
  </code></pre>
  
  <p>But the array filtered is always returnin empty, even if the console inside the <code>indexOf</code> verification prints the correct object on the console.</p>
  
  <p>What am I doing wrong here? Because it's filtering properly, I have manually checked it, but it doesn't add to the new filtered array.</p>