var sum=0
for(var i=3i<=6i++)
{
sum+=Math.pow(i,3)
}
var arr1 = [1,2,3,4,5,6,7,8,9]var arr = arr1.map(function(item,index,array){
return item*item*item
})
返回的新数组arr则是元素立方运算后的新数组
<%@page contentType="text/htmlcharset=gbk" %><html>
<head>
<script>
function show(){
var maxRow =10
var strTbl = "<table border='1'><tbody>"
var strTbody = ""
strTbody+="<tr align='center'><th>给定数字</th><th>平方值</th><th>立方值</th><tr>"
for(var i = 0i <=maxRowi++){
strTbody +="<tr align='center'>"
strTbody+="<td>"+i+"</td><td>"+i*i+"</td><td>"+i*i*i+"</td>"
strTbody += "</tr>"
}
strTbl = strTbody + "</tbody></table>"
document.getElementById("tableDiv").innerHTML = strTbl
}
</script>
</head>
<body onload="show()">
<div id="tableDiv"></div>
</body>
</html>