So this is a bit of a sticky question, but here goes. I’m trying to collect results so that I can aggregate arrays within a single call. Here’s the code that is problematic
Here’s the issue, I need to append to the collection variable, but this code simply overwrites it for each iteration of the loop (likely expected). I wondered if there was a way to use an array like function so that instead of overwriting collection variables, it would simply add to them, and when the loop is finished, I would have a complete array of all the return values.
If you want to aggregate the responses over time, you’re almost there. I would do the array manipulation outside of your forEach loop to do something like this:
One would think that this would work but it doesn’t. The problem is that the loop doesn’t finish before the variable is called (due to the asynchronous nature of javascript). So the collectionvariable is null as the calls haven’t been made.