I have following array which contains strings;
let data = ["2018-1", "2018-5", "2018-11", "2018-2", "2018-10", "2018-12"];
these strings are composed of number (year and month).
Can you tell me why didn't work following function for sorting? I need sort this array from latest date to oldest. In this case from "2018-12" to "2018-1".
I am using lodash in whole project so I try use it here as well.
var result = _.sortBy(data, function(i) {
var x = i.split("-").map(Number);
return [x[0], x[1]];
});
can you tell me why this code doesn't work and how to fix it? Thanks.
.sort()
method on the array? It's more flexible than the lodash sort.Uncaught ReferenceError: _ is not defined
What do you mean with "this code doesn't work", show me the error, please