4.解构赋值.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 1.数组
  11. // let arr = [1,2,3,'55',true];
  12. // let [a,b,c,d,e] = arr;
  13. // console.log(a,b,c,d,e);
  14. // 2.对象
  15. // let obj = {
  16. // a1:1,
  17. // b2:"哈哈",
  18. // c3:function() {
  19. // console.log(this)
  20. // }
  21. // }
  22. // // console.log(obj.c())
  23. // let {a1,b2,c3} = obj;
  24. // console.log(a1,b2,c3)
  25. // 3.函数
  26. // function fn1() {
  27. // return {
  28. // name:"LiLi",
  29. // age: 10,
  30. // eat:function() {
  31. // console.log(this);
  32. // }
  33. // }
  34. // }
  35. // let {name,age,eat} = fn1();
  36. // console.log(name,age,eat);
  37. // 4.字符串
  38. let str = 'hello';
  39. let [q,w,r,t,y] = str;
  40. console.log(q,w,r,t,y)
  41. </script>
  42. </body>
  43. </html>