Skip to content

Instantly share code, notes, and snippets.

@domfarolino
Created December 12, 2016 21:17
Show Gist options
  • Save domfarolino/bc94ce7c66444dd21d2028453b427319 to your computer and use it in GitHub Desktop.
Save domfarolino/bc94ce7c66444dd21d2028453b427319 to your computer and use it in GitHub Desktop.
Demonstrating how Array.prototype.forEach(...) works by using it on Objects
Object.prototype["0"] = "test0";
let obj = {"1": "test1", "2": "test2"};
for (let k in obj) console.log(k); // 1, 2, 0
Object.defineProperty(obj, 'length', {
value: 3,
enumerable: false,
writable: true,
configurable: false
});
Array.prototype.forEach.call(obj, i => {console.log(i)}) // test0, test1, test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment