I have this stripped code:
var dateFormat = ' *some date format* ';
var unixFormat = ' *the unix date format* '
function sorter(date, key) {
var result = date.sort(function(a, b) {
var date1 = a.key;
var date2 = b.key;
console.log(key); //returns "publishedDate"
console.log(date1); //returns undefined
var testDate = a.publishedDate;
console.log(testDate); //returns *some date*
var first = moment(date1, dateFormat).format(unixFormat);
var second = moment(date2, dateFormat).format(unixFormat);
return second - first;
});
return result;
};
var data = ' *array with entries such as "publishedDate: *some date*"* ';
var sorted = sorter(data, 'publishedDate');
I'm trying to set the variables date1 and date2 to the correct value. In this case, that would be "a.publishedDate" and "b.publishedDate".
The "publishedDate" part of the name is not constant, so I'm trying to pass this to the function, as you can see in the variable "sorted".
But when I do, I simply get undefined. Any ideas?