Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const someObject = {
- a: 1,
- perrito: 'Yolodog',
- aChar: 'a',
- }
- someObject[Symbol.iterator] = function() {
- let currentKey = 0;
- const keys = Object.keys(this);
- const { length } = keys;
- return {
- next: function() {
- return currentKey < length
- ? { value: this[keys[currentKey++]], done: false }
- : { done: true };
- }.bind(this),
- };
- };
- for (let item of someObject) { console.log(item); }
- // 1
- // Yolodog
- // a
Add Comment
Please, Sign In to add comment