@Wangww0925
2019-01-23T01:27:34.000000Z
字数 656
阅读 177
Array数组
数组元素最大值
Array.prototype.max = function (){
return Math.max.apply(null,this)
}
var arr = [1,50,62,85,3,9,46,12,30];
console.log(arr.max()); // 85
数组元素最小值
Array.prototype.min = function (){
return Math.min.apply(null,this)
}
var arr = [1,50,62,85,3,9,46,12,30];
console.log(arr.min()); // 1
数组元素最大值
Array.prototype.max = function (){
this.sort(function(a,b){
return b-a;
})
return this[0]
}
var arr = [1,50,62,85,3,9,46,12,30];
console.log(arr.max()); // 85
数组元素最小值
Array.prototype.min = function (){
this.sort(function(a,b){
return a-b;
})
return this[0]
}
var arr = [1,50,62,85,3,9,46,12,30];
console.log(arr.min()); // 1
作者 wendy
2019 年 1月 17日