title: Pass regex match to variable from console.log to display output in textbox
body: <p>What I want to achieve is to have the values stored in console.log passed to my textbox.</p>
  
  <p>Let's say my list (result) looks like this:</p>
  
  <pre><code>Line 1 abc apple abc
  
  Line 2 abc orange abc
  
  Line 3 abc banana abc
  
  Line 4 abc pear abc
  
  Line 5 abc apple abc
  </code></pre>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>textarea.value = console.log(`${match}`);
  </code></pre>
  
  <p>Here is my regex:</p>
  
  <pre><code>const regex = /^(.*(apple|banana).*)$/gm;
  const str = result;
  let m;
  
  while ((m = regex.exec(str)) !== null) {
      if (m.index === regex.lastIndex) {
          regex.lastIndex++;
      }
  
      m.forEach((match, groupIndex) =&gt; {
        if(match !== 'undefined' &amp;&amp; groupIndex &gt; 0)
          console.log(`${match}`);
      });
  }
  </code></pre>
  
  <p>This is the result I want in my textbox (which is now displayed in my console):</p>
  
  <pre><code>Line 1 abc apple abc
  
  Line 3 abc banana abc
  
  Line 5 abc apple abc
  </code></pre>