Created
April 20, 2022 19:39
-
-
Save anibal21/62050f3d74b51479bed118cbf0ce3263 to your computer and use it in GitHub Desktop.
Example of generator functions in JS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handsomeArray = [ | |
"Option1", | |
"Option2", | |
"Option3", | |
"Option4", | |
"Option5", | |
"Option6" | |
] | |
function * generatorFunction(array) { // Line 1 | |
for (item in array){ | |
yield array[item] | |
} | |
} | |
const generatorObject = generatorFunction(handsomeArray); | |
for (let item; item = generatorObject.next().value; ) | |
console.log(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment