You can't add to an existing array with spread inside [], you can only create a new array (like concat does):
mergedResults = [...mergedResults, ...events];
...which isn't very efficient if modifying the existing array is acceptable (but is common in situations where leaving the original array alone is important, such as when programming with immutable objects).
For that reason, you might use push with spread syntax instead:
mergedResults.push(...events);
Side note: You can use destructuring in the forEach parameter list rather than as a separate statement:
Promise.all(apiPromises).then(data => {
let mergedResults = [];
data.forEach(({events}) => {
// -----------^^^^^^^^
mergedResults.push(...events);
});
// ...presumably do something with `mergedResults` here...
});
Perhaps even throw in for-of:
Promise.all(apiPromises).then(data => {
let mergedResults = [];
for ({events} of data) {
mergedResults.push(...events);
}
// ...presumably do something with `mergedResults` here...
});
Or as with all array operations where you visit all elements, you can shoehorn this into reduce, but you don't gain anything by it, it just makes things more complicated:
Promise.all(apiPromises).then(data => {
let mergedResults = data.reduce((results, {events}) => {
results.push(...events);
return results;
}, []);
// ...presumably do something with `mergedResults` here...
});