I would like to sort an array of objects by two attributes.
The array is as follows:
var unidades = [{"id": 1, "numero": 3, "bloque": "F"},
{"id": 2, "numero": 101, "bloque": "A"},
{"id": 1, "numero": 1, "bloque": "F"},
{"id": 1, "numero": 5, "bloque": "C"},
{"id": 1, "numero": 1, "bloque": "A"}
];
I want to sort the array first by block and then by number, ascending. How can I do it ? Now I have a function that only orders me by block, but I need the number, which is the following:
function ordenarBloque(a,b) {
if (a.bloque < b.bloque)
return -1;
else if (a.bloque > b.bloque)
return 1;
else
return 0;
};
Any suggestions?
Thank you.