Working With ECMAScript 2019 Asynchronous Iteration Using “for-of”
How to use “for-of” loops in ECMAScript 2019
This article is focused on the concept of Asynchronous Iteration, which is available in ECMAScript 2019. The“for-of” loop is often used to iterate through the list of items inside a loop. We can now use the “for-of” loop in JavaScript to iterate through the list of Promises and provide the value received when the Promise is resolved.
Let's iterate through an array of numbers using the “for-of” loop:
The code above is a simple code that is iterating through the list of employeeSalaries
. The code, in this case, is synchronously iterating over data. Each iterated value represent a data value.
Creating a Simple Promise Using “New Promise”
The code below gives a simple way to create a Promise in JavaScript: