I have the following array:
let datas = ["nov/2018", "set/2018", "jan/2019", "dez/2018", "out/2018"]
when I execute
datas.sort()
he orders by alphabetical order, however, I must order first by the year and then by alphabetical order.
["dez/2018", "jan/2019", "nov/2018", "out/2018", "set/2018"]
Testing today I arrived at the following line of code:
var datas = ["mar", "abr", "jan", "dez", "set", "mai", "jun", "out", "jul"];
var datas_corretas = ["jan", "fev", "mar", "abr", "mai", "jun", "jul", "ago", "set", "out", "nov", "dez"];
var result = [];
datas_corretas.forEach(function ordenar(element, index){
var mes = datas.filter(function(valor){
return valor == datas_corretas[index];
});
result.push(mes[0]);
for(element of result){
if (element === undefined || element === null){
result.pop(element);
}
}
});
console.log(result);
That way I can sort the data, but the problem is when I use it with the year
var datas = ["mar/2018", "abr/2018", "jan/2019", "dez/2018", "set/2018", "mai/2018", "jun/2018", "out/2018", "jul/2018"];
Does anyone have any idea how I can resolve this?