I am digging into this & Object prototype (You Don't Know JS) and I found this tricky thing that blew my mind:
I created a literal Array (JS Arrays are objects) x = ['foo', 42, 'bar']
and added a property called baz like x.baz = 'baz'
. Then, in Chrome dev console, just typping x will display the following result: > (3) ["foo", 42, "bar", baz: "baz"]
. If I unfold the ">
", each value of the array has its own key like:
0: "foo"
1: 42
2: "bar"
baz: "baz"
What kind of JS-object-monster did I create? For and forEach loops do not count the baz property and bypass it.
Help would be very appreciated. Thank you!