I have parsed a CSV that slices like this:
data[0]
>>Date:08/23/2018, Organizer:RadioShack, Event:Promotion
I found a somewhat helpful question in: Find closest date in array with JavaScript, however I had trouble adapting it from an array of dates to dates stored within an array of objects. I have dates from data[0]
to data[10]
. It's not a terribly long dataset, however I would like to code it better than my current crude approach:
var dateArray = [];
dateArray[0] = data[0].Date;
dateArray[1] = data[1].Date;
…
console.log(dateArray.filter(function(d) {return d - today > 0; }))
That gives me all dates after today's date, which is a start, but I'm still falling short on finding the date closest to today.
Question: I thought maybe I could just write a for loop to give me that array faster, but I still wonder: is there a way I can find the date closest to today's date from an array of objects and store that date in:
var closestEventDate = ???