js get max value in (json) Array

// Max value in Array
var arr = [1,2,3,5,3,2];Math.max.apply(null, arr); // 5


// Max value in Jaon Array
var arr = [{"x":"8/11/2009","y":0.026572007},{"x":"8/12/2009","y":0.025057454},{"x":"8/13/2009","y":0.024530916},{"x":"8/14/2009","y":0.031004457}];
Math.max.apply(Math,arr.map(function(o){return o.y;}))
// 0.031004457

var arr = [{"a":1},{"a":2},{"a":3}];Math.max.apply(Math,arr.map(function(o){return o.a;}))
// 3
var arr = [{a:1},{a:2},{a:3}];Math.max.apply(Math,arr.map(function(o){return o.a;}))
// 3

 

你可能感兴趣的:(每天进步一点点,学习永无止境,max,纵观千象)