does anyone have any guides or tips on how to write a nested promises?
I am trying to turn the following nested for loop into a promise:
let arr = [1, 2, 3, 4, 5]
for (i = 0; i < arr.length ; i++) {
for (j = i + 1; j < arr.length ; j++) {
// call another asynchronous function
}
}
I thought about doing Promise.all, but the iterator in the inside for loop starts at j = i + 1 so I wasn't sure how to handle this with Promise.all.
Thanks in advance!
Promise.alltakes an array. It doesn't matter how many promises it contains, or how that number relates to your iteration counter. Do you know how to use it with non-nested loops?async/awaitsyntax will, but that leads to sequential instead of concurrent execution.