OiO.lk Blog javascript How to return the object with highest value from an array
javascript

How to return the object with highest value from an array


In an array I can find the max value like this

const Arr = [4,7,8,3,6];
const max = 
Math.max(...Arr);
console.log(max) // 8

Now I have a nested array like this,

const mainArr = [
{id:1, sub: "eng", no:3},
{id:2, sub: "kis", no:4},
{id:3, sub: "mat", no:5},
{id:4, sub: "sci", no:1},
{id:5, sub: "agr", no:4},
];

I want to return the sub array the highest no value

//{id:3, sub: "mat", no:5}

Kindly help



You need to sign in to view this answers

Exit mobile version