JavaScript array sort-function for both numeric and alphanumeric string -
i need sort array looks this:
var array = new array();<br /> array[0]="201206031245 firstitem";<br /> array[1]="201206020800 seconditem";<br /> array[2]="201206040604 itemthree";<br /> array[3]="201206031345 lastitem";<br /> how sort numerically , descending?
thanks in advance!
although .sort() default alphanumeric sort, data work numerically because array elements start numbers follow strict date/time format same number of digits. .sort() sort ascending though. provide own comparison function sort descending, or reverse results:
array.sort().reverse() for more information how .sort() works, e.g., provide own comparison function, have @ the documentation.
Comments
Post a Comment