Skip to content
Advertisement

How to return the element of an array containing the max value (index 1) (Javascript)?

Given the array below, how can I return the element containing the max number?

JavaScript

Expected Result

JavaScript

This is the function I’m trying with, but it only returns the number itself:

JavaScript

Appreciate any help!

Advertisement

Answer

Use Array.sort():

JavaScript

Note that this doesn’t handle the alphabetical order of the word.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement