Multi-index assignment.

T.J. Crowder tj.crowder at farsightsoftware.com
Mon Dec 4 19:36:10 UTC 2017


On Mon, Dec 4, 2017 at 7:21 PM, /#!/JoePea <joe at trusktr.io> wrote:
>
> I always run into situations where I'd like to assign some things from another array.
>
> ...
>
> could be written as
>
> ```js
> array[0, 1] = [1, 2]
> ```

No, it couldn't, because that's already valid syntax for setting
`array[1]` to the new array `[1, 2]`. (Comma operator turns `0, 1`
into `1`.)

You can use destructuring, but it's longer than the individual
assignments would be:

```js
[array[0], array[1]] = [1, 2];
```

-- T.J. Crowder


More information about the es-discuss mailing list