The real answer to this question in the case of any particular engine is likely to depend on the implementation of this mechanism. (Like the size of the difference, if any.)
However, there are invariants. For example, consider:
var obj = {a: "alpha", b: "beta"}; var name; for (name in obj) { console.log(obj[name]); } var arr = ["alpha", "beta"]; var index; for (index = 0; index < arr.length; ++index) { console.log(arr[index]); }
In the case of obj , the engine should use a mechanism to track those properties that you have already completed and which you don’t have, as well as filtering non-enumerable properties. For example, there is some kind of iterator object behind the scenes (and a way to define a specification, which can be a temporary array).
In the case of arr this is not so; you process this in your code in a very simple and efficient way.
The contents of the block of each cycle are the same: a search for the properties of an object. (In the latter case, theoretically, there is also a conversion of a number to a string.)
So, I expect that the only non-implementation answer would be the following: Extra overhead.
source share