I have an object:
[
{
name: "first name",
rolePosition: 85
},
{
name: "second name",
rolePosition: 91
}
]
How to select an object with the highest rolePosition value? In this situation is 91
>Solution :
The problem can be solved with Array.reduce() as follows:
const arr = [{ name: "first name", rolePosition: 85 }, { name: "second name", rolePosition: 91 }];
const result = arr.reduce((prev, curr) => prev.rolePosition > curr.rolePosition ? prev : curr , {});
console.log(result);