title: Sort an array so that null values always come last
body: <p>I need to sort an array of strings, but I need it so that null is always last. For example, the array:</p>
  
  <pre><code>var arr = [a, b, null, d, null]
  </code></pre>
  
  <p>When sorted ascending I need it to be sorted like <code>[a, b, d, null, null]</code> and when sorted descending I need it to be sorted like <code>[d, b, a, null, null]</code>.</p>
  
  <p>Is this possible? I tried the solution found below but it's not quite what I need.</p>
  
  <p><a href="https://stackoverflow.com/questions/19101573/how-can-one-compare-string-and-numeric-values-respecting-negative-values-with">How can one compare string and numeric values (respecting negative values, with null always last)?</a></p>