Skip to content

Instantly share code, notes, and snippets.

@Mayankgupta688
Created May 14, 2019 08:53
Show Gist options
  • Select an option

  • Save Mayankgupta688/958835939554eee7e6f4ed4bae4f5b80 to your computer and use it in GitHub Desktop.

Select an option

Save Mayankgupta688/958835939554eee7e6f4ed4bae4f5b80 to your computer and use it in GitHub Desktop.
function* customGenerator() {
yield 1;
yield 2;
yield 3;
}
let getIterator = customGenerator();
let nextValue = null;
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: 1, done: false }
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: 2, done: false }
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: 3, done: false }
nextValue = getIterator.next();
console.log(nextValue);
// Output is: { value: undefined, done: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment