获得在Javascript从阵列最小值? [英] Obtain smallest value from array in Javascript?
本文介绍了获得在Javascript从阵列最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
阵列justPrices有值,例如:
Array justPrices has values such as:
[0] = 1.5
[1] = 4.5
[2] = 9.9.
我如何在数组中返回最小的值?
How do I return the smallest value in the array?
推荐答案
乔恩Resig的说明在这篇文章这是如何通过扩展阵列原型,并调用底层 Math.min 的方法来实现。不幸的是并不需要一个数组,但参数变量号:
Jon Resig illustrated in this article how this could be achieved by extending the Array prototype and invoking the underlying Math.min method which unfortunately doesn't take an array but a variable number of arguments:
Array.min = function( array ){
return Math.min.apply( Math, array );
};
和则:
var minimum = Array.min(array);
这篇关于获得在Javascript从阵列最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文