const arr = [
{
"firstName": "maks",
"lastName": "jer",
"email": "joy@joy",
"phoneNumber": "0999561146",
"events": [
{
"title": "go",
"description": "out",
"startDate": "2011-09-02T21:00:00.000Z",
"endDate": "2012-09-02T21:00:00.000Z"
}
],
"eventsCount": 1
},
{
"firstName": "test",
"lastName": "test",
"email": "test@test",
"phoneNumber": "09899898",
"eventsCount": 2,
"events": [
{
"title": "go",
"description": "out",
"startDate": "2022-03-09T00:00:00.000Z",
"endDate": "2022-04-09T00:00:00.000Z",
},
{
"title": "lodash",
"description": "introducint",
"startDate": "2003-08-11T21:00:00.000Z",
"endDate": "2004-12-24T00:00:00.000Z"
}
],
}
];
arr.forEach((item) => {
if (item.events) {
item.events.sort((a, b) => {
const dateA = new Date(a.startDate);
const dateB = new Date(b.startDate);
return dateA - dateB;
});
}
});