Blogger Information
Blog 28
fans 0
comment 0
visits 15775
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
前端作业-07-09
︷肉園耔︷
Original
629 people have browsed it
  • 代码区.
    ```
    <!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>

    1. //push推动 从尾部添加字母
    2. let arr=[];
    3. console.log(arr.push("a"));
    4. console.log(arr);
    5. console.log(arr.push("b","c","d"));
    6. console.log(arr);
    7. //pop(无参数) 从尾部删除
    8. console.log(arr.pop());
    9. console.log (arr);
    10. //unshift从头部添加
    11. console.log(arr.unshift(1,2,3));
    12. console.log(arr);
    13. console.log (arr.shift());
    14. console.log(arr);
    15. arr=["html" ,"css","js"];
    16. let res=arr.join();
    17. console.log(arr);
    18. res=arr.join("---");
    19. console.log(res);

    les= arr.join(“</li><li>“);

    1. 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”]));

    1. //splice()实现数组的增删改查的操作
    2. arr=[1,2,3,4,5];
    3. res =arr.splice(3,1);
    4. console.log(res);
    5. //res=arr.splice(2,0,"html","css");
    6. res=arr.splice(3,0, ...["php","js"]);
    7. console.log(res);
    8. console.log(arr);
    9. //更新操作,即删除又新增
    10. res=arr.splice(2,1,"javascript");
    11. console.log(res);
    12. console.log(arr);
    13. //forEach() 对数组中的每一个成员使用一个回调方法进行处理

    /* const items = document.querySelectorAll(“li”);
    items.forEach(function(item){

    1. item.style.color="red";
    2. })*/
    3. 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 )
    {

    1. console.log("及格");

    }else{

    1. console.log("补考吧");

    }
    //多分支,当其他条件都不满足的是
    if(score >= 60 && score <80){

    1. console.log('不错');

    }else if(score > 80 && score<=100){

    1. console.log("学神");

    }else if(score >100 || score <0){
    console.log(“不能大于100分和小于0!”)
    }
    else {

    1. 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++;
}
*/

  1. </script>

</body>
</html>
```

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post