I have got a JSON Array as shown below
[{
"name": "Johnww",
"city": "New York",
"createDate": "2019-02-15T17:17:10.000+0530"
},
{
"name": "SAAA",
"city": "California",
"createDate": "2001-02-22T16:24:17.000+0530"
},
{
"name": "Vignesh",
"city": "India",
"createDate": "1984-03-02T12:48:55.000+0530"
}]
I am using KnockOut JS to display data in Sorted Order on basis of createDate
I have tried as following
var availablePeople = ko.observableArray(
[{
"name": "Johnww",
"city": "New York",
"createDate": "2019-02-15T17:17:10.000+0530"
},
{
"name": "SAAA",
"city": "California",
"createDate": "2001-02-22T16:24:17.000+0530"
},
{
"name": "Vigneshss",
"city": "India",
"createDate": "1984-03-02T12:48:55.000+0530"
}]
);
availablePeople.sort(function (left, right) { return left.createDate == right.createDate ? 0 : (left.createDate < right.createDate ? -1 : 1) })
ko.applyBindings(availablePeople);
http://jsfiddle.net/E7xPM/393/
But its displaying wrong results , could you please let me know how to fix this ? Thank you