Returns the item with the maximum value of key, or undefined for an empty array. Items where the key value is null or undefined are skipped.
key
undefined
null
The array to search.
The key to compare (string, number, or Date).
maxBy([{ age: 25 }, { age: 30 }, { age: 20 }], "age") // => { age: 30 }maxBy([], "age") // => undefined Copy
maxBy([{ age: 25 }, { age: 30 }, { age: 20 }], "age") // => { age: 30 }maxBy([], "age") // => undefined
Returns the item with the maximum value of
key, orundefinedfor an empty array. Items where the key value isnullorundefinedare skipped.