Get last line from a textarea on keypress
<p>I have a textarea field and on every keypress, I would like to push the last line in the textarea to an array.</p>

<p>Currently, I am constructing the array on every keypress to get the last line in the textarea. Is there a way to optimize this? Meaning, get last line in the textarea without having to construct an array.</p>

<pre><code>jQuery('#mytextarea').keypress(function() {
    lines = jQuery('#mytextarea').text().split("\n");
    lastLine = lines[lines.length - 1];
</code></pre>

<p>});</p>

<pre><code>if(.. some condition ..) {
myArray.push(lastLine);
</code></pre>
