I have an array of objects. I want to get the max out of the number attribute from the array:
[
{number: 1000, name: "Josh"},
{number: 2000, name: "Joker"},
{number: 3000, name: "Batman"}
]
I'm using this solution but I keep getting NAN:
const max = arr.reduce((a, b) => Math.max(a.number, b.number));
My goal is to get the max and then store it in a variable
const x = { number: 3000, name: "Batman"}
How would I achieve it with reduce? It seems like it is only working with array of numbers.