I have an array that I need to sort based on the sortPosition
value for a specific rotaTypeId
value.
The current rotaTypeId
is 1ebe7766-4a6b-4157-a998-00ebae24d662
so the expected result would show Sally first with Joe second.
I have tried looping over the outer array and for each element, grabbing its rotaTypeAccountEmployees
inner array. Then checking if the current rotaTypeId
value matched up.
That is as far as I got as I wasn't sure how to return an updated/sorted array.
Here is my array:
[
{
"object": "accountEmployee",
"accountEmployeeId": "c80b2d75-6091-423c-b51b-41cef265046a",
"employee": {
"object": "employee",
"employeeId": "c3832cff-ac4c-4133-ad29-a00ca8fd25f6",
"firstName": "Joe",
"surname": "Bloggs",
"email": "joe@bloggs.com"
},
"salary": 16286.40,
"hourlyRate": 7.83,
"weeklyContractHours": 40,
"rotaTypeAccountEmployees": [
{
"object": "rotaTypeAccountEmployee",
"rotaTypeId": "1ebe7766-4a6b-4157-a998-00ebae24d662",
"sortPosition": 2
},
{
"object": "rotaTypeAccountEmployee",
"rotaTypeId": "01d8ec46-d1cf-49e2-b992-840dfdb03a83",
"sortPosition": 1
}
]
},
{
"object": "accountEmployee",
"accountEmployeeId": "bdde68a4-7df0-431b-b108-db5c26ca7208",
"employee": {
"object": "employee",
"employeeId": "724c4c4c-978d-4f62-9345-28219153e728",
"firstName": "Sally",
"surname": "Bloggs",
"email": "sally@bloggs.com"
},
"salary": 16286.40,
"hourlyRate": 7.83,
"weeklyContractHours": 40,
"rotaTypeAccountEmployees": [
{
"object": "rotaTypeAccountEmployee",
"rotaTypeId": "1ebe7766-4a6b-4157-a998-00ebae24d662",
"sortPosition": 1
},
{
"object": "rotaTypeAccountEmployee",
"rotaTypeId": "01d8ec46-d1cf-49e2-b992-840dfdb03a83",
"sortPosition": 2
}
]
}
]