I have an array of hashes like this:
[
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2019-02-01T00:01:01.001Z",
"MeasureValue": -1
},
{
"Address": 26,
"AlertType": 1,
"Area": "West",
"MeasureDate": "2016-04-12T15:13:11.733Z",
"MeasureValue": -1
},
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2017-02-01T00:01:01.001Z",
"MeasureValue": -1
}
.
.
.
]
And I need to find the most recent date but return the Address from the corresponding hash. I've got the code that finds the newest date:
let newest = new Date(Math.min.apply(null, data.map(function(e) {
return new Date(e.created_at);
})));
most_recent = newest;
But I can't seem to get the address to return. The code I've written just returns the date or address from the
let findEarliest = (name) => {
let nameIndex = 0;
data.forEach((date) => {
if(date.created_at.includes(most_recent));
nameIndex = data.indexOf(date);
});
return data[nameIndex].name;
};
Any help would be appreciated.