Blogger Information
Blog 19
fans 0
comment 6
visits 19041
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS 数组对象解构,流程控制方法
葵花宝典
Original
904 people have browsed it

JS 数组对象解构,流程控制方法

  1. JS 引用字符串时, 可以用单引或双引号, (这是重点)可以用反引号, 用这个时,里面的字符不需要转意,比较常用.
    字符串拼接用 + 号,
    用插值模式时, 引号加号都不用, $()里可以直接写变量
    比如:
  1. let site = "PHP中文网";
  2. site = `${site}(www.php.cn)`;

输出结果为: PHP 中文网(www.php.cn)

  1. 数组,对象解构

    解构要求等号两边类型一致
    . 对象解构
    ({name,age}={name:”jack”,age:28});

  2. 循环
    javascrip 角本示例:
  1. <script>
  2. //插值模式拼接字符串
  3. let site = "PHP中文网";
  4. site = `${site}(www.php.cn)`;
  5. console.log(site);
  6. //解构对象, 把对象的值赋给左边的变量
  7. ({ name, age } = { name: "jack", age: 30 });
  8. console.log(name);
  9. console.log(age);
  10. //解构数组,用变量接收到了数组中的值
  11. let arr = ["red", "green", "blue"];
  12. [c1, c2, c3] = arr;
  13. console.log(c1);
  14. console.log(c2);
  15. console.log(c3);
  16. //流控
  17. //1.分支判断if, 在判断时, 并且&&, 或||
  18. if (1 > 2) {
  19. console.log("这是不可能的");
  20. } else {
  21. console.log("1大于2是假");
  22. }
  23. //2.多分支switch case break
  24. switch (6) {
  25. case 5:
  26. console.log("值为5时进入");
  27. break;
  28. case 6:
  29. console.log("值为6时进入");
  30. break;
  31. }
  32. //3.while,先判断再执行,下面示例不执行
  33. let i = 4;
  34. while (i < 3) {
  35. console.log(i);
  36. i++;
  37. }
  38. //4.do while 先执行再判断,输出4
  39. do {
  40. console.log(i);
  41. i++;
  42. } while (i < 3);
  43. //5.for(){} 示例如下
  44. for (let i = 0; i < 3; i++) {
  45. console.log(i);
  46. }
  47. //6.for in 能循环取对象, 也能遍历数组
  48. let obj1 = { name: "jack", age: 20 };
  49. //依次输出name和age的值
  50. for (let k in obj1) {
  51. console.log(obj1[k]);
  52. }
  53. //7.for of 在ES6中所有集合遍历都统一了,集合要求是迭代类型集合
  54. //不能遍历自定义对象,因为自定义对象没有迭代属性
  55. //手可加了迭代属性后就可以遍历了
  56. //示例遍历数组,输出red green blue
  57. for (let v of arr) {
  58. console.log(v);
  59. }
  60. </script>
Correcting teacher:天蓬老师天蓬老师

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