Jquery: Get Maximum value in An Array of Numbers

34,910

if by highest number you mean max value you don't need jQuery. You could do:

var myArray = [9,4,2,93,6,2,4,61,1];
var maxValueInArray = Math.max.apply(Math, myArray);
Share:
34,910
Julio Fong
Author by

Julio Fong

Updated on May 12, 2020

Comments

  • Julio Fong
    Julio Fong almost 4 years

    With jquery, how can I get the maximum value in an array or numbers?

    Example:

    var myArray = [1,4,7,3,12,0]
    

    Expected Output:-

    maximum value = 12

  • DiverseAndRemote.com
    DiverseAndRemote.com over 8 years
    Using ES6 you could do Math.max( ...myArray );