142
rated 0 times
[
143]
[
1]
/ answers: 1 / hits: 8106
/ 4 Years ago, wed, september 2, 2020, 12:00:00
I am sorting my array in JavaScript based on names after then I am sorting it based in joinDate
but somehow it is not checking for joiningDate
.
Unfortunately, I can't use an if-else condition - I only want to use ternary operators.
My code is like this:
person.sort(((a, b) => (a.name > b.name) ? 1 : (a.joinDate > b.joinDate) ? 1 : -1));
It is sorting the names but not sorting the joinDate
property
My list look like this:
{
"data": [
{
"id": "fdsf",
"name": "Julie",
"joinDate": "01/10/2019"
},
]
}
More From » arrays