Hello! I'm Kamijo from Development Department🔋
In this article, we will introduce JavaScript's "Split Assignment".
I would like to summarize the article as clearly as possible. Thank you very much for your continued support.
Click here for table of contents
- 1. what is split assignment?
- 2. partitioning and assignment of arrays
- 3. object partitioning and assignment
- 4. rest syntax and split assignment
What is Split Assignment?
The Destructuring assignment syntax is a JavaScript expression that allows you to take a value from an array or a property from an object and assign it to a separate variable.
MDN web docs
Split Array Assignment
The split assignment of an array is the same as the split assignment at the beginning of the
Write variable declarations like array literals on the left side, and write arrays on the right side.
See the Pen
yLJqWWv by kamijodev (@kamijodev)
on CodePen.
If the number of arrays is not enough, it will be undefined.
See the Pen
Split assignment 2 by kamijodev (@kamijodev)
on CodePen.
Split object assignment
It's the same as the split assignment of an array.
Write variable declarations like object literals on the left side and objects on the right side.
See the Pen
Split substitution 3 by kamijodev (@kamijodev)
on CodePen.
Rest Syntax and Split Assignment
It can be combined with the rest syntax to aggregate the rest of the values.
In Japan, it seems to be called residual substitution.
For more information on Rest Syntax, click here.
What are "spread syntax" and "rest syntax" in JavaScript?
See the Pen
Split substitution 4 by kamijodev (@kamijodev)
on CodePen.