Let’s say I have an array of objects, like so:
| |
I want to get the latest date.
The following solution will do the trick:
| |
...trades.map is the property spread notation. It ‘spreads’ out an array into a list of arguments. Basically removes the square brackets.
In my case, trades.map(trade => new Date(trade.date)) will return an array of dates. Literally this:
[Date Wed Apr 24 2019 02:25:43 GMT+0800 (Singapore Standard Time), 1: Date Fri May 24 2019 02:25:43 GMT+0800 (Singapore Standard Time)]
The ... before, will convert this array into simply 2 arguments, which you pass into Math.max() which will return you the latest. Then you of course create a new date out of it.
Brilliant.