for(var i = 1 i <=100 i++){
if(i%2 != 0) arr.push(i)
}
document.write(arr.join())
var arr=[]for(var i=1i<=100i++){
if(i%2!=0){
arr.push(i)
}
}
for(var i=0i<5i++){
// document.write(arr.slice(i*10,(i+1)*10)+"</br>")
obj.innerHTML+=arr.slice(i*10,(i+1)*10)+"</br>"//不想写在document可以用这条
}
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var num = []
// 随机生成20个1~100的数
for(var i = 0i<40i++){
num[i] =parseInt(Math.random()*100)
}
//判断是否能被2整除,删除
for(var i = 0i<40i++){
if(num[i]%2 == 0){
delete num[i]
}
}
// 遍历打印
for(var x in num){
document.writeln(num[x])
}
</script>
</body>
</html>
有点小bug,大概就是这样,我纯手写的