Skip to main content

Posts

Showing posts with the label javascript sorting

Decoding the date sorting in Javascript, efficient faster and native way.

Coming from the previous post  (   http://www.developerscloud.org/2014/05/decoding-underscore-js-sortby-sorting.html ) ,  where we have used the underscore to sort the array, with the limitation of sorting in descending order, I will show you in below post how to sort effectively using javascript native functionality. Lets use the same array we have in the previous post. var datesArray = ['6-01-2014','2-01-2014', '4-01-2014', '5-01-2014', '3-01-2014', '1-01-2014']; datesArray is now [" 6-01-2014 ", " 2-01-2014 ", " 4-01-2014 ", " 5-01-2014 ", " 3-01-2014 ", " 1-01-2014 "] Running the for loop making each item of array a date type object. for(var i = 0; i< datesArray.length; i++){ datesArray[i] = new Date(datesArray [i]); } After which datesArray will become [Sun Jun 01 2014 00:00:00 GMT+0530 (India Standard Time), Sat Feb 01 2014 00:...