Skip to content
Advertisement

Compare date and time in array of objects

I’m trying to compare the date and time to manipulate my data. I need to check which is the latest data by checking updated_at key inside object.

Below I have given the scenario.

JavaScript

I’m trying like this, but how to use moment here to compare which is latest.

JavaScript

But I’m not getting the expected result as below.

JavaScript

How can I do this by using map() or reduce()?

Advertisement

Answer

You should check it map and get the max date index. and then set its value to true;

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement