Skip to content

Instantly share code, notes, and snippets.

@Tombarr
Created May 7, 2019 00:55
Show Gist options
  • Save Tombarr/6a7423586ad9b0b3b0b1239ecf821d39 to your computer and use it in GitHub Desktop.
Save Tombarr/6a7423586ad9b0b3b0b1239ecf821d39 to your computer and use it in GitHub Desktop.
Make all Objects iterable in ES6
Object.prototype[Symbol.iterator] = function() {
let props = Object.getOwnPropertyNames(this);
return {
next: () => {
let name = props.shift();
let done = (name === undefined);
let value = (done) ? undefined : [name, this[name]];
return { value, done };
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment