Multiple Variables Holding Data - Which has the Highest Value in JavaScript?

To fetch the highest value, use the Math.max() from JavaScript. Since, we want the one with maximum value, use the Object.values.


const studentMarksDetails=
const maximumMarks = Math.max(...Object.values(studentMarksDetails));
console.log("The highest marks="+maximumMarks);
for (const key of Object.keys(studentMarksDetails)){
   if (studentMarksDetails[key] == maximumMarks) {
      console.log(`The Object='${key}'`);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo91.js.


This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo91.js
The highest marks=79
The Object='marks3'