I have JS object defined as follows -
var item = {};
item[guid()] =
{
symbol: $('#qteSymb').text(),
note: $('#newnote').val(),
date: $.datepicker.formatDate('mm/dd/yy', dt) + " " + dt.getHours() + ":" + minutes,
pagename: getPageName()
};
At some point in my app I am getting a list of those (Items) back from chrome.storage and I would like to be able to sort it based on the date
Here is what I am doing
var sortable = [];
$.each(Items, function (key, value) {
if (value.symbol == $('#qteSymb').text() || all) {
sortable.push([key, value]);
}
});
console.log(sortable);
sortable.sort(function (a, b) {
a = new Date(a[1].date);
b = new Date(b[1].date);
return a > b ? -1 : a < b ? 1 : 0;
});
console.log(sortable);
It doesn't seem to work. The first and second console.log(sortable); is the same. I have tried changing return a > b ? -1 : a < b ? 1 : 0; to return a < b ? -1 : a > b ? 1 : 0; just to see if I am getting any change to sortable but nothing happens...
Thank you~
dt.getTime()as well and simply sort by it like:return a[2] - b[2];new Date(a[1].date)? -> useconsole.log(a.toString()+' and '+b.toString())in the function.