user1027620
user1027620

Reputation: 2785

Sort two types of objects in a single array

I have an array with meeting objects having property utc_start. I also have an array with reminder objects having property utc_datetime.

After combining them as such:

    combined = [];
    combined = combined.concat(meetings);
    combined = combined.concat(reminders);

Is it possible to sort them? Each by using the different property?

combined.sort((a, b) => {

});

Thanks.

Upvotes: 1

Views: 33

Answers (1)

hsz
hsz

Reputation: 152226

You can try with:

combined.sort((a, b) => {
  const utcA = a.utc_start || a.utc_datetime;
  const utcB = b.utc_start || b.utc_datetime;

  // compare utcA with utcB
});

Upvotes: 4

Related Questions