I have an array of objects like below. How to return an array of objects containing the minimum value of bidAmount?
[
{userId:2,bidAmount:9200},
{userId:3,bidAmount:8500},
{userId:4,bidAmount:8100},
{userId:5,bidAmount:8100}
]
Expected result:
[
{userId:4,bidAmount:8100},
{userId:5,bidAmount:8100}
]
I tried Array.reduce to find minimum but it returns only one object
var min = result.reduce(function(res, obj) {
return (obj.bidAmount < res.bidAmount) ? obj : res;
});
//Returns {userId: 4, bidAmount: 8100}
How can this be achieved?