Skip to content
Advertisement

Get the Second Highest Date in JavaScript/ES6

I have a problem getting the second highest date in ES6. I’m using moment.js too. Its supposed to be getting the id of 3.

JavaScript
JavaScript

Advertisement

Answer

You should use custom sort function as:

JavaScript

There is no need to use find when you are reverseing the array and getting the index 1 from it.

Note: I deliberately change the order of the datas array

JavaScript
JavaScript

or you can directly find the second largest after sort. There is no need to reverse the array

JavaScript

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