Skip to content

Instantly share code, notes, and snippets.

@guest271314
Created December 10, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/c42ce434665b6a47e1465d83eb99b946 to your computer and use it in GitHub Desktop.
Save guest271314/c42ce434665b6a47e1465d83eb99b946 to your computer and use it in GitHub Desktop.
generator-with-indexes.js
// https://stackoverflow.com/questions/53687210/how-to-iterate-over-a-generator-with-indexes
function* myGen(){
let i = 10;
while(i<20) {
i+=1;
yield i;
}
}
for(let [index, j] of [...myGen()].entries()) { //<-- I want .entries() but for a Generator
console.log(index, j)
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment