Skip to content

Instantly share code, notes, and snippets.

@AndriBG
Forked from sachalifs/Symbol.iterator.js
Created February 20, 2024 00:22
Show Gist options
  • Save AndriBG/24dae3feb7462e68a6b98942f8eae1c3 to your computer and use it in GitHub Desktop.
Save AndriBG/24dae3feb7462e68a6b98942f8eae1c3 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