To add property to an array of objects with JavaScript, we use the map
method.
For instance, we write
const mapped = results.map((obj) => ({ ...obj, active: "false" }));
to call results.map
with a callback that returns an object with the original object obj
‘s properties spread into a new object and we add the active
property to it.
Then an array is returned with the original objects in results
with the active
property added.