Array wont print outside For Each Element

Hi i am trying to make a function that gets the value of each dropdown and then adds the id of the item they selected to the array, if there is one selected in that dropdown.
But it only does it when you do console.log in the .then() however this the returns an array each time a item is added but i only want it when it has finished that. So i moved the console.log to be after it has finished adding all the items but the array is empty like nothing was added.
Screenshot 2023-08-03 210656
Niall

A: the forEach returns a Promise, not a value. While it is still resolving all those queries, the program flow continues (its asynchronous, remember?), hits the end of the function, when you try to log the contents, which must be empty still because you did not wait for all Promises to resolve,
B: why that looped query? It’s quite expensive. Why don’t you just put the id inside the array from the dropdown and get it from there. Lot quicker and less expensive. You are not limited to the name-value pairs that Wix specifies, you can “overload” the array with extra pairs, the dropdown will just pick out the pairs it needs, and later on, you use the rest.