I have a textarea field and every keystroke, I would like to press the last line in textarea on an array.
I am currently creating an array on each keypress to get the last line in the text box. Is there any way to optimize this? Value, get the last line in the text field without creating an array.
jQuery('#mytextarea').keypress(function() { lines = jQuery('#mytextarea').text().split("\n"); lastLine = lines[lines.length - 1];
});
if(.. some condition ..) { myArray.push(lastLine);
source share