
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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.
Example
const studentMarksDetails= { marks1:78, marks2:69, marks3:79, marks4:74 } 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}'`); break; } }
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo91.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo91.js The highest marks=79 The Object='marks3'
- Related Articles
- Assign multiple variables to the same value in JavaScript?
- Which one of the following has the highest calorific value?KeroseneBiogasLPGPetrol
- The water holding capacity is highest in ______ soil.
- How can data that has multiple variables be visualized using Seaborn in Python?
- Which of the following fuels has the highest calorific value?Diesel, Methane, CNG, Coal, Petrol
- Which of the following fuels has the highest calorific value?natural gasliquefied petroleum gascoal gashydrogen gas
- Returning the highest value from an array in JavaScript
- Which UPSC Optional Subject has the Highest Success Rate
- How to concatenate multiple string variables in JavaScript?
- Returning the highest number from object properties value – JavaScript
- What is the best way of declaring multiple Variables in JavaScript?
- Figuring out the highest value through a for in loop - JavaScript
- According to Java Operator precedence, which operator has the highest precedence?
- Highest and lowest value difference of array JavaScript
- How to extract the first highest occurring value in an R data frame column?

Advertisements