As I'm trying to get an object with all the names with the highest values, I am only getting one value and name rather than all existing names with the same highest value? // { name: 'Stephen', total: 85 } Any help would be appreciated.
const students = [
{ name: 'Andy', total: 40 },
{ name: 'Seric', total: 50 },
{ name: 'Stephen', total: 85 },
{ name: 'David', total: 30 },
{ name: 'Phil', total: 40 },
{ name: 'Eric', total: 85 },
{ name: 'Cameron', total: 30 },
{ name: 'Geoff', total: 30 }];
const max = Math.max(...students.map(e => e.total))
const result = students.find(student => student.total === max)
console.log(result)//{ name: 'Stephen', total: 85 }
totaland to find out owners of maxtotal). If that suits better to the purpose, upvote/accept are greatly welcome ;)