Splitting text in textarea by new lines (including empty lines) into javascript array
问题 I'm trying to split the text inside Splitting textarea data by new lines. My current code works, except for a small requirement: The resulting array must include empty lines as well. <script> $(function(){ var lines = []; $.each($('#data').val().split(/\n/), function(i, line){ if(line){ lines.push(line); } }); console.log(lines); }); </script> <textarea id="data"> I like to eat icecream. Dogs are fast. The previous line is composed by spaces only. The last 3 lines are empty. One last line. <