Jquery: Get Maximum value in An Array of Numbers [closed]
Asked Answered
H

1

16

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

Hawsepiece answered 4/2, 2013 at 18:58 Comment(4)
.length is plain JavaScriptMoonscape
this is not array.lenght, lenght here is like array count.Hawsepiece
You really need to be more clear in your question, then. A couple examples would help us understand what you mean.Moonscape
Do you mean the last element? The maximum value? The number of elements in the array?Lentamente
L
61

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);
Lunatic answered 4/2, 2013 at 19:1 Comment(1)
Using ES6 you could do Math.max( ...myArray );Lunatic

© 2022 - 2024 — McMap. All rights reserved.