return value inside foreach
<p>So this is very weird, I have a foreach function like this:</p>

<pre><code>  let cookieValue = '';

  cookieList.forEach(function(cookieItem) {
    const cookieParts = cookieItem.split('=');
    const value = cookieParts[1];
    const key = cookieParts[0];
    if (key.trim() === cookieName) {
      cookieValue = value;
      return cookieValue;
    }
  });

  return cookieValue;
</code></pre>

<p>which works fine, however when I change the lines inside the if statement to a single line:</p>

<pre><code>return value;
</code></pre>

<p>It returns undefined always.</p>

<p>Any ideas of what can be happening here?</p>