I have the following data
shots = [
{id: 1, amount: 2},
{id: 2, amount: 4}
]
Now I\'m trying to get the object which
There are couple of mistakes
shot.amount
instead of shot
Finally
shots.reduce((max, shot) =>
shot.amount > max ? shot.amount : max, 0);
Demo
var shots = [
{id: 1, amount: 2},
{id: 2, amount: 4}
];
var output = shots.reduce((max, shot) =>
shot.amount > max ? shot.amount : max, 0);
console.log( output );
Edit
If the entire object has to be returned, then initializer should be an object with amount
property
var shots = [
{id: 1, amount: 2},
{id: 2, amount: 4} ];
var output = shots.reduce((max, shot) =>
shot.amount > max.amount ? shot : max , {amount:0});
console.log( output );