I am dealing with an array of hashes structured 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
}
.
.
.
]
My task is to identify the most recent date in the array and return the corresponding Address value. I have successfully found the newest date using the following code:
let newest = new Date(Math.min.apply(null, data.map(function(e) {
return new Date(e.created_at);
})));
most_recent = newest;
However, I am struggling to retrieve the Address value. The code I've written only 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 assistance on this issue would be greatly appreciated.