Skip to content

Instantly share code, notes, and snippets.

@nigerdyanes
Forked from sachalifs/Symbol.iterator.js
Created October 18, 2022 14:21
Show Gist options
  • Save nigerdyanes/225aab934310c2a04869015b4a2103fb to your computer and use it in GitHub Desktop.
Save nigerdyanes/225aab934310c2a04869015b4a2103fb to your computer and use it in GitHub Desktop.
var arr = ['Sacha', 'Og', 'Haru'];
arr[Symbol.iterator] = function *() {
var i = this.length - 1;
while (i >= 0) {
yield this[i];
i--;
}
}
for (var value of arr) {
console.log(value);
}
console.log([...arr]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment