Blogger Information
Blog 28
fans 0
comment 1
visits 13390
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS学习之 解构赋值
centos
Original
418 people have browsed it

解构赋值

解构赋值包含数组解构、对象解构、函数解构赋值

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>数组解构</title>
  8. </head>
  9. <body></body>
  10. <script>
  11. // 数组解构
  12. let [name, age] = ["张峰", "33岁"];
  13. console.log(name, age);
  14. //迭代更新
  15. [name, age] = ["老王", "44岁"];
  16. console.log(name, age);
  17. //参数不足添加默认值,参数过多,归并参数,用...
  18. [a, b, c, d, e, ...f] = [1, 2, 4, 5, 6, 7, 8, 9];
  19. console.log(a, b, c, d, e, f);
  20. // 对象解构不用let时,等号左边禁止出现大括号,必须使用大括号时
  21. // 用括号包住转为表达式
  22. ({ name, age } = { name: "张峰", age: "33岁" });
  23. console.log(name, age);
  24. // 函数解构传参
  25. function getUser({ name, age }) {
  26. console.log(name, age);
  27. }
  28. getUser({ name: "老吴", age: "66岁" });
  29. </script>
  30. </html>

下一篇写DOM

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