138
rated 0 times
[
144]
[
6]
/ answers: 1 / hits: 118775
/ 9 Years ago, thu, april 23, 2015, 12:00:00
I need to sort an array of strings, but I need it so that null is always last. For example, the array:
var arr = [a, b, null, d, null]
When sorted ascending I need it to be sorted like [a, b, d, null, null]
and when sorted descending I need it to be sorted like [d, b, a, null, null]
.
Is this possible? I tried the solution found below but it's not quite what I need.
How can one compare string and numeric values (respecting negative values, with null always last)?
More From » javascript