Trim line breaks from a string in Javascript without frameworks
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript">How do I trim a string in javascript?</a>  </p>
</blockquote>



<p>While I solved the issue I was experiencing when I was looking for a solution a few moments ago I was not able to find anything that actually worked. This is mostly intended to be an easy-to-find question/answer for others to find as I am surprised by the lack of the absence any on-topic pages on the WWW in general.</p>

<p>So <strong><em>using JavaScript without any frameworks how would you trim line breaks</em></strong>? Trim as being defined by PHP, removing the leading and ending line breaks while preserving line breaks after the first non-white-space character and until though not beyond the last non-white-space character.</p>

<p>By default most people will want to know how to <strong><em>remove both leading/ending line breaks as well as white-space spaces too</em></strong> though some may want to retain the white-space spaces while trimming just the white-space line-breaks. It also generally helps to see two working examples and how they relate when they both work for people learning code so I'll accept the answer for trimming both white-space line-breaks <em>and</em> white-space spaces while voting up how to trim just the leading/ending line breaks while preserving white-space spaces (which may or may not be included in the main answer).</p>
