I want to sort by 2 key values โโof object in javascript
[
{
"min": 8,
"price": 2
},
{
"min": 3,
"price": 1
},
{
"min": 9,
"price": 4
},
{
"min": 360,
"price": 9
}
]
I want to sort from descending to ascending according to min and price values. the code i wrote
const sortCardItems = cardItems
.slice()
.sort(
(a, b) =>
parseInt(a.min, 10) - parseInt(b.min, 10) &&
parseInt(a.price, 10) - parseInt(b.price, 10),
);
but it only sorts by price I want to get a result like this
e.g.
[
{
"min": 3,
"price": 2
},
{
"min": 4,
"price": 3
},
{
"min": 5,
"price": 4
},
{
"min": 360,
"price": 9
}
]