Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
manual iterable
// add iterator to user object
let user = {
name: "sam", totalReplies: 17, isBlocked: false
};
user[Symbol.iterator] = function(){
let properties = Object.keys(this);
let count = 0;
let isDone = false;
let next = () => {
if(count >= properties.length){
isDone = true;
}
let value = this[properties[count++]];
return { done: isDone, value:{value} };
};
return { next };
};
// iterate user object
let values = [...user];
console.log(values);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.