简单的jQuery代码段可获取特定索引值数组中的最大值。
数据集。
var data = Array();
data[0] = {"apples":1, "pears":2, "oranges":3};
data[1] = {"apples":3, "pears":3, "oranges":5};
data[2] = {"apples":4, "pears":1, "oranges":6};
功能。
//获取特定索引数组中的最大值
//用法:getHighestVal(data,index)
//数据=数组
// index =要分析的数组的索引
函数getHighestVal(数据,索引)
{
$ .each(数据,函数(i,v)
{
thisVal = v [index];
max =(max <thisVal)? thisVal:max; }); 返回最大值 } var maximum = getHighestVal(data,'apples'); console.log(最高); [/ js] 示例:
因此,在此示例中,我们希望获得“苹果”的最高价值。
From: https://www.sitepoint.com/jquery-highest-array-specific-index/