How to return a spread operator in a map arrow function in one line [duplicate] How to return a spread operator in a map arrow function in one line [duplicate] arrays arrays

How to return a spread operator in a map arrow function in one line [duplicate]


When returning a literal object from an arrow function construct (a lambda), you have to wrap it in parentheses so that it's seen as an expression:

data.map(item => ({...item, active: false}));

map is only useful if you need a different array.

But there's a simpler solution here. You don't have to reassign all items and data. You should simply do

data.forEach(item => item.active=false)