How to Get Index of the Max Value in Array of Objects ? Last Updated : 05 Aug, 2025 Comments Improve Suggest changes Like Article Like Report When dealing with arrays of objects in JavaScript, it's common to need the index of the object with the maximum value based on a certain property. Below are the approaches to get the index of the max value in an array of objects: Table of Content Using a LoopUsing Array.reduce() MethodUsing a LoopThis approach iterates through the array of objects using a simple for loop. It keeps track of the index of an object with the maximum value based on the specified property. Example: The below code uses a for loop to iterate over the array of objects and get the index of the max value. JavaScript function indexOfMax(arr, prop) { let max = -Infinity; let index = -1; for (let i = 0; i < arr.length; i++) { if (arr[i][prop] > max) { max = arr[i][prop]; index = i; } } return index; } const employees = [ { name: 'John', salary: 50000 }, { name: 'Alice', salary: 70000 }, { name: 'Bob', salary: 60000 } ]; const maxSalaryIndex = indexOfMax(employees, 'salary'); console.log("Index of employee with highest salary:", maxSalaryIndex); OutputIndex of employee with highest salary: 1 Using Array.reduce() MethodArray.reduce() is a powerful method in JavaScript used to reduce the elements of an array to a single value. It executes a provided function for each value of the array and accumulates a single result. Syntax:Array.reduce(callbackFunction, initialValue)Example: The below code explains the use of the reduce() method to get the index of the max value in an array of objects. JavaScript function indexOfMax(arr, prop) { return arr.reduce( (maxIndex, current, currentIndex, array) => { return current[prop] > array[maxIndex][prop] ? currentIndex : maxIndex; }, 0); } const people = [ { name: 'Alice', age: 30 }, { name: 'Bob', age: 40 }, { name: 'John', age: 35 } ]; const maxAgeIndex = indexOfMax(people, 'age'); console.log("Index of person with maximum age:", maxAgeIndex); OutputIndex of person with maximum age: 1 Create Quiz Comment R rohitdalvi Follow 0 Improve R rohitdalvi Follow 0 Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like