<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>站长特效_js数组求和和最大值方法_站长特效网</title>
<meta name="keywords" content="站长,网页特效,网页特效代码,js特效,js脚本,脚本,广告代码,zzjs,zzjs.net,www.zzjs.net,站长特效 网" />
<meta name="description" content="www.zzjs.net,站长特效网,站长必备js特效及广告代码。大量高质量js特效,提供高质量广告代码下载,尽在站长特效网" />
</head>
<body>
<a href="http://www.zzjs.net/">站长特效网</a>,站长必备的高质量网页特效和广告代码。zzjs.net,站长js特效。<hr>
<script type="text/javascript">
//求和
Array.prototype.sum = function () {
for (var sum = i = 0; i < this.length; i++)sum += parseInt(this[i]);
return sum ;
};
//求最大值
Array.prototype.maxima = function () {
for (var i = 0, maxValue = Number.MIN_VALUE; i < this.length; i++)parseInt(this[i]) > maxValue && (maxValue = this[i]);
return maxValue;
};
//应用
var arr = [1,21,3,4,22,45,60,7,32];
alert(arr.join("+") + "=" + arr.sum()); alert(arr.join("|") + "中, 最大的数是:" + arr.maxima());
</script>
</body>
</html>