`return Object.assign([...people], { [idx]: transform(people[idx]) })`
should work for you with no additional syntax.On Wed, Jan 18, 2017 at 8:30 PM, Jeremy Martin <[email protected]> wrote: > 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 [ > ...people, > [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. > > Thanks! > > -- > Jeremy Martin > @jmar777 > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

