Created
December 12, 2016 21:17
-
-
Save domfarolino/bc94ce7c66444dd21d2028453b427319 to your computer and use it in GitHub Desktop.
Demonstrating how Array.prototype.forEach(...) works by using it on Objects
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
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