//最小值
Array.prototype.min
=
function()
{
var
min
=
this[0]
var
len
=
this.length
for
(var
i
=
1
i
<
len
i++){
if
(this[i]
<
min){
min
=
this[i]
}
}
return
min
}
//最大值
Array.prototype.max
=
function()
{
var
max
=
this[0]
var
len
=
this.length
for
(var
i
=
1
i
<
len
i++){
if
(this[i]
>
max)
{
max
=
this[i]
}
}
return
max
}
//数组长度
var
array
=
new
array(1,2,3,2,4,55,2)
alert(array.length)//输出7
希望本文所述对大家JavaScript程序设计有所帮助。
还是很简答的//最小值
Array.prototype.min = function() {
var min = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] <min){
min = this[i]
}
}
return min
}
//最大值
Array.prototype.max = function() {
var max = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] >max) {
max = this[i]
}
}
return max
}
希望对你有帮助
var a=[1,2,3,5]
alert(Math.max.apply(null, a))//最大值
alert(Math.min.apply(null, a))//最小值
多维数组:
var a=[1,2,3,[5,6],[1,4,8]]
var ta=a.join(",").split(",")//转化为一维数组
alert(Math.max.apply(null,ta))//最大值
alert(Math.min.apply(null,ta))//最小值