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)) }) 

demo


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -