// 求对象中的最大值
var o ={
a:1,
b:3,
c:4,
d:6,
e:8
}
var max = 0;
var maxKey = '';
for(var key in o){
if(max<o[key]){
max = o[key];
maxKey = key;
}
}
console.log('对象中的最大值是:'+max+',他的属性名是:'+ maxKey);
// 求数组中的最大值
var arr = [1,3,5,6,2];
var max = arr[0];
var maxKey = '';
for(var key in arr){
if(max<arr[key]){
max = arr[key];
maxKey = key;
}
}
console.log('数组中的最大值是:'+max+',他的索引值是:'+ maxKey);
// 求数组里面的最大值
var arr = [1,5,2,9,4,8];
var max = Math.max.apply(null,arr);
var max = Math.max.apply(Math,arr);
console.log(max);