Wrap each line with li
<p>This is how I split the content of a textarea element into br-lines for displaying:</p>

<pre><code>function linebreak(string) {
    return string.replace(/(?:\r\n|\r|\n)/g, '&lt;br /&gt;');
}
</code></pre>

<p>So this string...</p>

<pre><code>Line 1\nLine 2
</code></pre>

<p>...gets...</p>

<pre><code>Line 1&lt;br&gt;
Line 2&lt;br&gt;
</code></pre>

<p>But now I need each line wrapped as a <code>li</code>-element. The result should be:</p>

<pre><code>&lt;li&gt;Line 1&lt;/li&gt;
&lt;li&gt;Line 2&lt;/li&gt;
</code></pre>

<p>This is how I would do that:</p>

<pre><code>let result = '';
string.split('\n').forEach(function(line) {
    result += '&lt;li&gt;' + line + '&lt;/li&gt;';
});
return result;
</code></pre>

<p>But is this the correct way to do that?</p>