title: Split string in javascript by lines, preserving newlines?
body: <p>How would I split a javascript string such as <code>foo\nbar\nbaz</code> to an array of lines, while preserving the newlines? I'd like to get <code>['foo\n', 'bar\n', 'baz']</code> as output;</p>
  
  <p>I'm aware there are numerous possible answers - I'm just curious to find a stylish one.</p>
  
  <p>With perl I'd use a <a href="http://www.perlmonks.org/?node_id=518444" rel="nofollow noreferrer">zero-width lookbehind assertion</a>: <code>split /(?&lt;=\n)/</code>, but they are not supported in javascript regexs.</p>
  
  <p>PS. Extra points for handling different line endings (at least <code>\r\n</code>) and handling the missing last newline (as in my example).</p>