In a for of
loop, I want to get a value defined (not empty) before I continue to the next iteration.
Currently, I do a setTimeout()
and "hope" that the value is available after 3 seconds. Poor practice.
Is there a way to pause the loop iteration until the value is available, and then continue the loop?
// get a tags in array
const $j_object = $(".name");
for (const element of $j_object) {
// timeout
await new Promise(resolve => setTimeout(resolve, 3000));
// get value
value_name = await GM.getValue("value_name");
// wait until value_name is defined until we continue...!
}