查找数组对象属性值最大

var arr=[
       {a:12,b:10,c:3,d:15},
       {a:8,b:9,c:9,d:15},
       {a:1,b:5,c:12,d:55},
       {a:8,b:9,c:9,d:11},
       {a:10,b:10,c:3,d:5}
       ]
var val={};
for (var i = 0; i < arr.length; i++) {
    if(!val){  
         val=arr[i]    
    }
    for(var obj in arr[i]){
        if(val[obj]>arr[i][obj]){   //容器容器对应的obj值大于arr对应obj,则跳出当前for循环
            break;
        }
        val=arr[i]
    }
};
console.log(val)

 

posted @ 2018-01-05 15:45  兼容IE8  阅读(425)  评论(0编辑  收藏  举报