ES6 allows you to extract values from arrays and objects and assign values to variables according to a certain pattern. This is called deconstructed assignment.

<! DOCTYPEhtml>
<html>

<head>
  <meta charset="utf-8">
  <title>Deconstruction assignment</title>
</head>

<body>
  <script>
    // ES6 allows you to extract values from arrays and objects and assign values to variables according to a pattern. This is called deconstructed assignment.
    
    // 1
    const F4 = ["Eldest brother"."The second brother." "."Three elder brother"."Four elder brother"];
    let [a, b, c, d] = F4;
    // This is equivalent to declaring four variables a,b,c, and d respectively corresponding to "big brother "," second brother "," third brother ", and" four brother ".
    console.log(a + b + c + d); // Big brother two elder brother three elder brother four elder brother
    
    // 2
    const F3 = {
      name: "Eldest brother".age: 22.sex: "Male".xiaopin: function () { / / the commonly used}}let { name, age, sex, xiaopin } = F3;
    // Note that {} is used to deconstruct objects.
    console.log(name + age + sex + xiaopin);// The big brother is 22 male
    xiaopin();  // This method can be called normally
  </script>
</body>

</html>
Copy the code

Application scenario: If object methods and array elements are frequently used, destruct assignment can be used.