This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = { | |
sub: { | |
array: [] | |
}, | |
[Symbol.iterator]() { | |
let index = 0; | |
return { | |
next: () => { | |
// you could insert custom logic here, like stepping 3 by 3, filtering, etc. | |
if ( index >= this.sub.array.length ) return { done: true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = { | |
sub: { | |
array: [1,2,3,4,5,6,7,8,9] | |
}, | |
*[Symbol.iterator]() { | |
for (let i = 0; i < this.sub.length; i++) { | |
yield this.sub[i]; | |
} | |
} | |
} |
OlderNewer