I have array of objects, that I get by array.filter. Now I want to make .map() function on this array and change specific object property in all objects in this array. Something like this
.map(task => task.description = task.description.replace(...);
But this gives me array of strings, not array of objects with this updated property. How to make this returning whole objects with just description updated?
CodePudding user response:
Avoid to use "=" after arrow function if you do not explicite the return value
Try this :
const test = tasks.map(task => {
task.description = task.description.replace(...)
return task
});
console.log(test)
CodePudding user response:
remember that, once you've .filter
followed by .map
, better to use .reduce()
otherwise you'll loop twice on the same array.