Skip to content

Instantly share code, notes, and snippets.

@vldvel
Created February 28, 2018 10:52
Show Gist options
  • Save vldvel/527f6d4d5be90ffa9de2a69f65451c0f to your computer and use it in GitHub Desktop.
Save vldvel/527f6d4d5be90ffa9de2a69f65451c0f to your computer and use it in GitHub Desktop.
function * iterateArray(arr) {
for (let i in arr)
yield arr[i];
}
const iterArr = iterateArray([0,1,2]);
iterArr.next(); // {value: 0, done: false}
iterArr.next(); // {value: 1, done: false}
iterArr.next(); // {value: 2, done: false}
iterArr.next(); // {value: undefined, done: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment