Destructuring for Array-like objects

Jordan Harband ljharb at gmail.com
Wed Mar 20 03:08:41 UTC 2019


`const [a, b] = Array.from(anyArraylikeObject);`

On Tue, Mar 19, 2019 at 7:22 PM Frederick Stark <coagmano at gmail.com> wrote:

> This already works with an iterator, because array destructuring uses the
> iterator protocol
>
> const [a, b] = {
>   0: "ayy",
>   1: "bee",
>   length: 2,
>   *[Symbol.iterator]() {
>       let i = 0;
>       while (i < this.length) {
>           yield this[i]
>           i++
>       }
>   },
> };
>
>
>
> On Mar 20 2019, at 11:59 am, Sultan <thysultan at gmail.com> wrote:
>
> Afford array destructuring to Array-like objects.
>
> const [a, b] = {0: a, 1: b, length: 2}
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190319/35560058/attachment.html>


More information about the es-discuss mailing list