title: Splitting text in textarea by new lines (including empty lines) into javascript array
body: <p>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 <strong>must include empty lines</strong> as well.</p>
  
  <pre><code>&lt;script&gt;
  $(function(){
      var lines = [];
      $.each($('#data').val().split(/\n/), function(i, line){
          if(line){
              lines.push(line);
          }
      });
      console.log(lines);
  });
  &lt;/script&gt;
  
  
  &lt;textarea id="data"&gt;
  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.
  &lt;/textarea&gt;
  </code></pre>
  
  <p>The current result is:</p>
  
  <blockquote>
    <p>["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."]</p>
  </blockquote>
  
  <p>What it <strong>should</strong> be:</p>
  
  <blockquote>
    <p>["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."]</p>
  </blockquote>