在这里我想获得这个多维数组的最大值,其中 tax_value 更大。
0:{id: "61", tax_value: "2.00000000"}
1:{id: "81", tax_value: "12.00000000"}
这里我使用这段代码获取数组。
var array = new Array();
if (typeof $('select[id^=item_tax]') !== "undefined")
{
$('select[id^=item_tax]').each(function (i, e)
{
if ($(e).val() > 0)
{
array.push({id: $(e).val(), tax_value: $(e).find('option:selected').data('value')});
}
});
}
console.log(array);//multi dimensional array is coming as output
如何从这个数组中获取最大值。
最佳答案
要返回最大 tax_value
,请使用 map
var maxTaxValue = Math.max.apply( null, array.map( s => s.tax_value ) );
用于返回最大 tax_value
的整个对象。
var obj = array.find( s => s.tax_value == maxTaxValue )
关于javascript - js获取多维数组最大值的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48801395/