One of the best features (and maybe weakness) of javascript it's the flexibility, there are many ways to solve a problem.
One common problem is to update the content of an array of objects.
What options do we have available to perform this task?
There are immutable and mutable ways.
Immutable are the methods that do not change the original array but creates a modified copy of it.
In the other hand, mutable methods change the original array in place.
In the mutable side you can just use the indexed access to update the value in place, but what are immutable ways to accomplish the same?
Enters the array methods map, findIndex and slice
Map iterates over the array and by using a callback function allow access to the items. Map creates a new array with the content return it by the cover function.
Another way to update the content of one of the items by not knowing the index is by using the findIndex method.
This method accepts a test function that check certain condition and returns the index of the element.
To update the content you'll use it together with slice.
Using array slice to get two portions of the array, before and after the index you can change the value and then merge the pieces together using the spread operator.