snowshoes
8/21/2017 - 9:21 AM

find object from array by max property - js

find object from array by max property - js

// https://stackoverflow.com/questions/39037005/get-object-from-array-by-max-property
var latest = values.reduce(function(l, e){
  return l.startedate > e.startdate ? {value: l.value, startdate: l.startdate} : {value: e.value, startdate: e.startdate}
})

// function
function latest(values){
    return values.reduce(function(l, e){
        return l.startdate > e.startdate ? {value: l.value, startdate: l.startdate} : {value: e.value, startdate: e.startdate};
    });
}