Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of array destructuring #3118

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ <h2 id="Description">Description</h2>
console.log(z); // 2
</pre>

<p>Similarly, you can destructure arrays on the left-hand side of the assignment</p>

<pre class="brush: js">const [firstElement, secondElement] = list;
// is equivalent to:
// const firstElement = list[0];
// const secondElement = list[1];
</pre>

<p>This capability is similar to features present in languages such as Perl and Python.</p>

<h2 id="Examples">Examples</h2>
Expand All @@ -74,7 +82,7 @@ <h4 id="Basic_variable_assignment">Basic variable assignment</h4>

<h4 id="Assignment_separate_from_declaration">Assignment separate from declaration</h4>

<p>A variable can be assigned its value via destructuring separate from the variable's declaration.</p>
<p>A variable can be assigned its value via destructuring, separate from the variable's declaration.</p>

<pre class="brush: js">let a, b;

Expand Down