I have these object :
var obj1 = {
endDateInMs : 125000001
};
var obj2 = {
endDateInMs: 125000000
};
var obj3 = {
endDateInMs: 125000002
};
and an array containing these objects :
var array1 = [obj1, obj2, obj3];
I would like to sort array1 by date of object. I would like to have the more recent first and the oldiest at the end of the array.
I do the following but it does'nt work :
function compare(a,b) {
if (a.endDateInMs < b.endDateInMs) {
return -1;
}
else if (a.endDateInMs > b.endDateInMs) {
return 1;
}
}
var arrayOfHistoryForThisItem = wall_card_array[item];
var newArraySorted = arrayOfHistoryForThisItem.sort(compare);
var lastElement = newArraySorted[0];
return 0incompare(a,b).return 0incompare(a,b).