DEV Community

Cover image for Execute Promise-based code in order over an array

Execute Promise-based code in order over an array

Tobias Barth on April 18, 2019

The problem I recently faced a problem: I had a list (an array) of input data and wanted to execute a function for every item in that li...
Collapse
 
anduser96 profile image
Andrei Gatej

‘How would I use .then() and jump to the next iteration step within that then?’.

I’d get the next item in the array before using then() on the current item.

I really liked your idea, thank you for sharing!

Collapse
 
4nduril profile image
Tobias Barth

Thanks for your reply. I would love to see your version in code. Because I fear I do not understand how that would work with an unknown array length.

I'm happy that you liked my take on that.

Collapse
 
anduser96 profile image
Andrei Gatej

Hi! Here is what I meant.

I also linked the resource where I've found out the idea.
Hope you find it useful.