const arr = [object, object, object, object, object]
arr.forEach(x => {
object.proterty = myFunction();
})
function myFunction() {
//click something
//return what you click;
}
my code looks like this, the forEach loop it doesnt wait for the return value from myFunction
You can try to wrap it in a promise and than use async/await
like this
const arr = [object, object, object, object, object]
arr.forEach(x => {
object.proterty = myFunction();
})
function myFunction() {
return new Promise((resolve) => {
//click something
const clickedItem = ....
//resolve what you click;
resolve(clickedItem)
})
}
I think a forEach loop is not what you want. A forEach loop is designed to iterate over an Array one time for each element. There is no way to pause a loop besides with throwing an exception.
If you want something like this maybe take a look in the following methods:
Array.prototype.every()
Array.prototype.some()
Array.prototype.find()
Array.prototype.findIndex()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach