代码区.
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数组常用的方法</title>
</head>
<body>
<ul>
<li>html</li>
<li>css</li>
<li>js</li>
</ul>
<script>//push推动 从尾部添加字母
let arr=[];
console.log(arr.push("a"));
console.log(arr);
console.log(arr.push("b","c","d"));
console.log(arr);
//pop(无参数) 从尾部删除
console.log(arr.pop());
console.log (arr);
//unshift从头部添加
console.log(arr.unshift(1,2,3));
console.log(arr);
console.log (arr.shift());
console.log(arr);
arr=["html" ,"css","js"];
let res=arr.join();
console.log(arr);
res=arr.join("---");
console.log(res);
les= arr.join(“</li><li>“);
console.log(les);
console.log(‘<ul><li>$<res></ul></li>‘);
//document.body.insertAdiacentHTML(“beforeend”,html);
//cancat():
console.log(“hello”.concat(“php.cn”));
console.log([“hello”].concat([“php.cn”]));//splice()实现数组的增删改查的操作
arr=[1,2,3,4,5];
res =arr.splice(3,1);
console.log(res);
//res=arr.splice(2,0,"html","css");
res=arr.splice(3,0, ...["php","js"]);
console.log(res);
console.log(arr);
//更新操作,即删除又新增
res=arr.splice(2,1,"javascript");
console.log(res);
console.log(arr);
//forEach() 对数组中的每一个成员使用一个回调方法进行处理
/* const items = document.querySelectorAll(“li”);
items.forEach(function(item){item.style.color="red";
})*/
document.querySelectorAll("li").forEach(xxx=>(xxx.style.color="red"));
//filter()对数组中的每个使用回调方法进行处理,只返回数据为true的元素
arr=[1,2,3,4,5,6,7,8];
res=arr.filter(a=>!(a%2));
console.log(res);//reduce();归并操作,将数组中的所有元素指定的回调处理一个单一结果返回
arr=[1,2,3,4,5];
res=arr.reduce(function(prev,curr){
console.log(prev,curr);
return prev+curr;
});res=arr.reduce((prve,curr)=>prve+curr);
console.log(res);arr=[5,6,7,8,9,12,13,14,15];
res=arr.reduce(function(prev,curr){
console.log(prev,curr);
return prev+curr;
});
res=arr.reduce((prve,curr)=>prve+curr);
console.log(res);
/*
let score=101;
//单分支
if(score >60) {console.log(“及格”)};//双分支
if(score >=60 )
{console.log("及格");
}else{
console.log("补考吧");
}
//多分支,当其他条件都不满足的是
if(score >= 60 && score <80){console.log('不错');
}else if(score > 80 && score<=100){
console.log("学神");
}else if(score >100 || score <0){
console.log(“不能大于100分和小于0!”)
}
else {console.log("补考吧");
}
//4.多分支简化
score=61;
switch(true){
case score >=60 && score<80:
console.log("不错");
break;
case score >80 && score<=100:
console.log(“学神”);
break;
case score >100 ||score<0:
console.log(“成绩不能大于100或者小于0”);
break;
default:console.log(“补考吧”);
}
const colors=[“red”,”green”,”blue”];
let i=0;
//i< colore.length 循环条件,
while (i<colors.length){
console.log(colors[i]);
}
i=i+1;
const colors=[“red”,”green”,”blue”];
i=0;
while(i>colors.length){
console.log(colors[i]);
i++;
}
*/
</script>
</body>
</html>
```