I need to sort the main data by the oldest created account. In the example below, the first element in the list would be id = 2. That's because the id = 2 contains the oldest created account (named account3, which was created at 2020-10-05, while the other accounts have been created after that date). I'm using nodejs. Is there an es-function that can solve this problem in an easy way?
The object data looks like this:
{
"data": [{
"id": 1,
"accounts": [{
"id": 333,
"data": {
"name": "account1",
"createdAt": "2020-10-07T09:27:28.032Z"
}
}]
}, {
"id": 2,
"accounts": [{
"id": 334,
"data": {
"name": "account2",
"createdAt": "2020-10-06T09:27:28.032Z"
}
}, {
"id": 335,
"data": {
"name": "account3",
"createdAt": "2020-10-05T09:27:28.032Z"
}
}]
}]
}