json - Sorting an array of JavaScript objects according to date -
i have file json:
var point = [{ "id": 1, "name": "a", "lastupdate": "2016-07-08", "position": [36.8479648, 10.2793332]},{ "id": 1, "name": "a", "lastupdate": "2016-07-07", "position":[ 36.8791039, 10.2656209]},{ "id": 1, "name": "a", "lastupdate": "2016-07-09", "position": [36.9922751, 10.1255164]},{ "id": 1, "name": "a", "lastupdate": "2016-07-10", "position": [36.9009882, 10.3009531]},{ "id": 1, "name": "a", "lastupdate": "2016-07-04", "position": [37.2732415, 9.8713665]}];
how can sort objects lastupdate(it's date) property in ascending , descending order using javascript?
try this
point.sort(function(a, b) { return (new date(b.lastupdate)) - (new date(a.lastupdate)) })
Comments
Post a Comment