function sortNum(a,b) {
return a - b; //正序:a-b 逆序:b-a
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
return a - b; //正序:a-b 逆序:b-a
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
2019-05-23
// 逆序输出字符串
var myarr1= "hey guys!";
document.write(myarr1.split("").reverse().join("") + "<br>")
// 逆序输出数组
var ax = new Array(3)
ax[0] = "1"
ax[1] = "2"
ax[2] = "3"
document.write(ax.reverse())
var myarr1= "hey guys!";
document.write(myarr1.split("").reverse().join("") + "<br>")
// 逆序输出数组
var ax = new Array(3)
ax[0] = "1"
ax[1] = "2"
ax[2] = "3"
document.write(ax.reverse())
2019-05-23
最赞回答 / weixin_慕少0311380
给p标签加个ID名字,如<p id="p1">这是内容,会被覆盖,怎么办</p>然后在函数里面加上这句就可以啦:document.write(p1.innerHTML+"</br>");
2019-05-23
// 随机生成10个(1-100)的随机数
var x = [];
for(let i = 0;i<10;i++){
x[i] = Math.round((Math.random())*100);
document.write(x[i] + "<br/>")
}
var x = [];
for(let i = 0;i<10;i++){
x[i] = Math.round((Math.random())*100);
document.write(x[i] + "<br/>")
}
2019-05-23
var c = [3.3,-0.1,-9.9,8.9];
for(let i=0;i<c.length;i++){
document.write(Math.round(c[i]) + " ")
}
for(let i=0;i<c.length;i++){
document.write(Math.round(c[i]) + " ")
}
2019-05-23
var b = [3.3,-0.1,-9.9,8.9];
for(let i=0;i<b.length;i++){
document.write(Math.floor(b[i]) + " ")
}
for(let i=0;i<b.length;i++){
document.write(Math.floor(b[i]) + " ")
}
2019-05-23
// 这里使用循环节省一点代码(手动滑稽)
var a = [3.3,-0.1,-9.9,8.9]
for(let i=0;i<a.length;i++){
document.write(Math.ceil(a[i])+ " ")
}
var a = [3.3,-0.1,-9.9,8.9]
for(let i=0;i<a.length;i++){
document.write(Math.ceil(a[i])+ " ")
}
2019-05-23
// 定义数组
var infos = [
['小A','女',21,'大一'], ['小B','男',23,'大三'],
['小C','男',24,'大四'], ['小D','女',21,'大一'],
['小E','女',22,'大四'], ['小F','男',21,'大一']
]
//遍历数组,筛选符合条件的数据
for(let i=0;i<infos.length;i++){
if(infos[i].indexOf("大一")>=0&&infos[i].indexOf("女")>=0){
document.write(infos[i]);
}
}
var infos = [
['小A','女',21,'大一'], ['小B','男',23,'大三'],
['小C','男',24,'大四'], ['小D','女',21,'大一'],
['小E','女',22,'大四'], ['小F','男',21,'大一']
]
//遍历数组,筛选符合条件的数据
for(let i=0;i<infos.length;i++){
if(infos[i].indexOf("大一")>=0&&infos[i].indexOf("女")>=0){
document.write(infos[i]);
}
}
最新回答 / qq_慕运维7313110
二维数组和一位数组道理一样,一位数组存放的直接就是数据,而二维数组存放的是数组,相当于在array[0]=1的基础上,变为array[0]=new Array();把数字1变为可以存放数据的一维数组。相当于这样array[0]={1,2,3,4}
2019-05-22
最赞回答 / qq_疯狂的人_0
<...图片...> <script type="text/javascript"> var a,b; //a,b为要传入myfunction()的参数,return为返回结果a+b; //myfunction()相当于一个加法,return相当于等号,返回myfunction()的结果 function myfunction(a,b){ ...
2019-05-22
function average(scores){
var sum=0;
var count=0
for(i=0;i<=scoreStr.length;i++){
if(scoreStr.charAt(i)==":"){
sum=sum+parseInt(scoreStr.substr(i+1,2));
count++
}
}
return sum/count;
}
var sum=0;
var count=0
for(i=0;i<=scoreStr.length;i++){
if(scoreStr.charAt(i)==":"){
sum=sum+parseInt(scoreStr.substr(i+1,2));
count++
}
}
return sum/count;
}