Array DestructuringValues in arrays are destructured based on their index . The variable can be named anything you want, but the variable name associated with the index is how it is assigned. We can also assign values to variables that are already declared.
Nested Object and Array Destructuring Here's another example with an array of objects: You can destructure as deeply as you like: As you can see, keys a , b , and c are not implicitly defined, even though we pulled out nested values, firstElemOfC and remainingElementsOfC , from the array at c .
You need to use assignment without declaration syntax:
({
screenings,
size
} = source);
Babel REPL Example
From the linked docs:
The ( .. ) around the assignment statement is required syntax when using object literal destructuring assignment without a declaration
And obviously you need to use this as you can't redeclare a let
variable. If you were using var
, you could just redeclare var { screenings, size } = source;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With