<div dir="auto"><div dir="auto"><span style="font-family:sans-serif">T.J., thanks for pointing out that Object.assign provides the same functionality. I'd neglected to consider that the first argument needn't be a plain object.</span><br></div><div dir="auto"><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Interesting that folks seems to prefer the syntax variant more than I had expected.<br></div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">As for the application of providing a destructuring parallel.. well, you've convinced me it could be useful. :)</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Here's a spec question: must the keys specified be numbers? The application is questionable but I say anything could be allowed. E.g.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">```js</div><div dir="auto" style="font-family:sans-serif">const arr1 = [1,2,3]</div><div dir="auto" style="font-family:sans-serif">const arr2 = [...arr1, foo: 'bar' ]</div><div dir="auto" style="font-family:sans-serif">```</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Or</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">```js</div><div dir="auto" style="font-family:sans-serif">const [ 1: middle, foo, ...arr3 ] = arr2</div><div dir="auto" style="font-family:sans-serif">console.log(middle, foo, arr3) // 2 "bar" [1, 3]</div><div dir="auto" style="font-family:sans-serif">```</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">So array rest spread would provide totally parallel functionality to object rest spread with the key difference that result objects are arrays instead of objects.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Thoughts?</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Ben</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">Le 10 juill. 2018 02 h 48, "T.J. Crowder" <<a href="mailto:tj.crowder@farsightsoftware.com">tj.crowder@farsightsoftware.com</a>> a écrit :<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">The standard library already handles doing array-copy-and-update as a one-liner via `Object.assign` (<a href="http://jsfiddle.net/ryqtvbdk/" target="_blank" rel="noreferrer">http://jsfiddle.net/ryqtvbdk/</a>):<br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```js</div><div style="text-decoration-style:initial;text-decoration-color:initial"><div><font face="monospace, monospace">const original = [1, 2, 3, 4];</font></div><div><font face="monospace, monospace">const updated = Object.assign([...original], {1: 4, 3: 42});</font></div><div><font face="monospace, monospace">// Or: <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">const updated = Object.assign([], original, {1: 4, 3: 42});</span></font></div><div><font face="monospace, monospace">console.log(updated); // [1, 4, 3, 42]</font></div></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```</div></div><br class="m_7347321376929111696gmail-Apple-interchange-newline">Like Isiah, I think I'd prefer it as syntax. I'm not an engine implementer so I have no idea how hard it would be to do this to an array initializer:</div><div><br></div><div>```js</div><div><font face="monospace, monospace">const original = [1, 2, 3];</font></div><div><font face="monospace, monospace">const updated = [...<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">original</span>, 1: 4];</font></div><div><font face="monospace, monospace">console.log(<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">updated</span>); // [1, 4, 3]</font></div><div>```</div><div><br></div><div>...but that's what I'd like to see. Parallels the object initializer. Currently invalid syntax, so safe to add from that perspective. And it enhances destructuring as well (since array initializer syntax is used for destructuring):</div><div><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```js</div><div><font face="monospace, monospace">const original = [1, 2, 3];</font></div><div><font face="monospace, monospace">const [1: foo, ...rest] = original;</font></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">console.log(foo); // 2</font></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">console.log(rest); // [1, 3]</span><br></font></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```<br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">(Note that `rest` is an array, whereas with an object destructuring pattern, it would be a non-array object.)</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">That syntax would also provide expressive creation of sparse arrays, e.g.:</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```js</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">const array = [2: 42];</font></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><font face="monospace, monospace">console.log(array); // [, , 42];</font></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">```</div><div class="signature-text"><br class="m_7347321376929111696gmail-Apple-interchange-newline"><div>-- T.J. Crowder<br></div></div></div>
</blockquote></div><br></div>