Javascript Jquery:获取数字数组中的最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14693568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:38:18  来源:igfitidea点击:

Jquery: Get Maximum value in An Array of Numbers

javascriptjqueryarraysnumbershighest

提问by Julio Fong

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

使用 jquery,如何获取数组或数字中的最大值?

Example:

例子:

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

Expected Output:-

预期输出:-

maximum value = 12

最大值 = 12

回答by DiverseAndRemote.com

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

如果按最高数字表示最大值,则不需要 jQuery。你可以这样做:

var myArray = [9,4,2,93,6,2,4,61,1];
var maxValueInArray = Math.max.apply(Math, myArray);