Blogger Information
Blog 41
fans 0
comment 0
visits 40993
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS数组解构|JS对象解构|JS常用的流程控制方法
幸福敲门的博客
Original
1446 people have browsed it

一、JS数组解构

实例:

  1. <script>
  2. // 数组解构
  3. let [a,[b, c], d,] = [400, [700,325],236];
  4. //console.log数组输出
  5. console.log(a, b, c,d);
  6. </script>

图示:
数组

二、JS对象解构

实例:

  1. // 对象解构
  2. <script>
  3. const user={
  4. name: '刘红军',
  5. age:23,
  6. sex:'女',
  7. mail:'lsc@cnsina.cn',
  8. school:'西南工学院'
  9. };
  10. ({ name, age,sex, mail,school} = { name: '刘红军', age: 23, sex:'女',mail:'lsc@cnsina.cn', school:'西南工学院'});
  11. // console.log 对象输出
  12. console.log(name,age,sex,mail,school);
  13. </script>

图示:
JS对象解构

三、流程控制方法

3.1 while 循环

while 循环,入口判断型,出口判断型

while入口判断型

  1. <script>
  2. // 循环
  3. const arr = [1, 2, 3, 4, 5];
  4. let i = 0;
  5. // 设置循环条件
  6. while (i < arr.length) {
  7. console.log(arr[i]);
  8. // 更新循环条件
  9. i++
  10. }
  11. </script>

图示:
while入口判断型

do while出口判断型

  1. <script>
  2. // 循环
  3. const arr = [1, 2, 3, 4, 5];
  4. i = 0;
  5. do {
  6. console.log(arr[i]);
  7. i++
  8. } while (i < arr.length);
  9. </script>

图示:
do while出口判断型

3.2 for 循环

for 循环,for in 数组和对象遍历,for of 数组遍历

for 循环

  1. <script>
  2. // for循环
  3. const arr = [6, 7, 8, 9, 10];
  4. i = 0;
  5. for (let i = 0; i < arr.length; i++) {
  6. console.log(arr[i]);
  7. }
  8. </script>

图示:
for循环

3.3对象遍历for in对象遍历for of 数组遍历

  1. <script>
  2. const arr = [1, 2, 3, 4, 5];
  3. // 初始化循环变量
  4. let i = 0;
  5. // 对象的遍历
  6. const user = {
  7. id: 5,
  8. name: '天蓬老师',
  9. email: 'tp@php.cn'
  10. };
  11. // for in 对象遍历
  12. for (let key in user) {
  13. console.log(`${key} => ${user[key]}`);
  14. }
  15. console.log('--------------------');
  16. // for - of 数组遍历
  17. for (let value of arr) {
  18. console.log(value);
  19. }
  20. </script>

图示:
遍历

3.4流程控制:分支
.单分支

  1. <script>
  2. let score = 70;
  3. if (score >= 60) console.log('及格了');
  4. </script>

. 双分支

  1. <script>
  2. let score = 30;
  3. if (score >= 60) console.log('及格了');
  4. else console.log('补考吧,兄弟');
  5. </script>

.多分支

  1. <script>
  2. let score = 90;
  3. if (score >= 60 && score < 80) console.log('合格');
  4. else if (score >= 81 && score <= 100) console.log('学霸');
  5. </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