To apply a function to each object in a JavaScript array, we use the map
method.
For instance, we write
const newArray = oldArray.map((e) => {
e.data = e.data.split(",");
return e;
});
to call oldArray.map
with a callback that sets the e.data
property in the oldArray
to a new value.
Then we return new object e
.
An array with each object e
in oldArray
modified is returned.