Proposal: Specifying an Index in Array Literals

Jeremy Martin jmar777 at
Thu Jan 19 04:30:07 UTC 2017

I just came across a use case where I wanted to create a shallow copy of an
array, while also updating the value at a particular index.

Is it feasible to extend the spread syntax for array literals in a manner
that supports updating values at a given index, similar to how the object
literal syntax supports updating a particular key?

Here's a quick example to illustrate:

    const idx = people.findIndex(/* some predicate */);

    if (idx >= 0) {
      return [
        [idx]: { ...people[idx], /* updates */ }

I suppose this implies a way to specify indexes in array literals in the
general case, but I can't think of any particularly compelling use cases
w/out the spread operator involved.


Jeremy Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list