0
I have an array of objects that returns 3 possible sensitivity values: "LOW", "MEDIUM", "HIGH". But with the code below it is ordering in "HIGH - MEDIUM and LOW" respectively in ascending order and I wish it to return "HIGH - MEDIUM and LOW". What can I correct in this code?
In this function I compare the received sensitivities in the array
orderItemsByOrderOption = (items) => {
switch (this.state.selectedOrderOption.column) {
case "sensitivity":
return items.sort((a, b) => {
if (a.sensitivity > b.sensitivity) {
return 1;
}
if (a.sensitivity < b.sensitivity) {
return -1;
}
// a must be equal to b
return 0;
});
Since they are objects you can create an attribute in the object to determine the level of sensitivity, using an integer number for example and sort by this attribute.
– Rafael Costa
This answers your question? Sort array within another array with Reactjs
– novic