Deconstruction assignment of "01" Array

Source: Internet
Author: User

"01"deconstruction assignment of arrays
Konjac Summary:Usage 1:var [a,b,c]=[1,2,3];
Usage 2: (can be nested arrays)let [foo, [[Bar], Baz]] = [1, [[2], 3]];
foo//1bar//2baz//3

Usage 3: (can variable name is empty, the number of variable value is more than the number of variables)Let [,, third] = ["foo", "Bar", "Baz"];
Third//"Baz"


Usage 4: (add 3 points before the variable, expressed as an array, note the value of the variable)Let [head, ... tail] = [1, 2, 3, 4];head//1tail//[2, 3, 4]
Usage 5: (when the number of variable values is less than the number of variables, the variable is undefined)Let [x, Y, ... z] = [' A '];x//' a ' Y//Undefinedz//[]
Knowledge 6: The variable is undefined when deconstructedKnowledge 7: When partially deconstructed,deconstruction can still succeed. Knowledge 8:if the right side of the equal sign is not an array (or, strictly speaking, not a ergodic structure), an error will be reported.
Knowledge 9: Deconstruction assignment applies not only to the Var command, but also to the Let and const commands.
Knowledge:The deconstruction assignment allows you to specify a default value. The default value can only be used if the variable is equal to (= = =) undefined.

Deconstruction assignment of "01" Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.