weibo_慕斯1183523
2021-11-30 16:43
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数组</title>
<script type="text/javascript">
//创建数组
var arr = ['*','##',"***","&&","****","##*"];
arr[7] = "**";
//document.write(arr.length);
//显示数组长度
var lineNum = 0;
//document.write(lineNum);
var lineTag = new Array(arr.length);
for(var i = 0; i < arr.length; i++){
lineTag[i] = 0;
//后续运行代码时发现程序在使用undefined的arr[6]时会停止
if(arr[i] == undefined){
continue;
}
//过滤含*号外的字符串下标,并把符合要求的字符串下标进行记录
var tag = 0;
//document.write(arr[i]);
for(var j = 0; j < arr[i].length; j++){
if(arr[i][j] != "*") tag =1;
}
//document.write(i + " " + tag + "<br>");
if(tag != 1){
lineNum++;
lineTag[i] = 1;
//document.write(i + " " + lineTag[i] + "<br>");
}
//else document.write(i + " " + lineTag[i] + "<br>");
}
//document.write(lineNum);
//保存仅含*号的几个字符串
//document.write(lineNum);
var newArr = new Array(lineNum);
var t = 0;
for(var i = 0; i < arr.length; i++){
if(lineTag[i] == 1){
newArr[t] = arr[i];
//document.write(newArr[t]);
t++;
}
}
// for(var i = 0; i < t; i++){
// document.write(newArr[i] + "<br>");
// }
//打印结果
t = 0;
while(t < lineNum){
for(var i = 0; i < newArr.length; i++){
if(newArr[i].length == t + 1){
document.write(newArr[i] + "<br>");
t++;
break;
}
}
}
</script>
</head>
<body>
</body>
</html>
你说得对
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题