3 ms·
I didn't say it was unclear or surprising, it's very obvious since an array is an object with the special length property. this is also obvious: var a = new A
by bryanrasmussen 10y ago
I didn't say it was unclear or surprising, it's very obvious since an array is an object with the special length property.
this is also obvious:
var a = new Array();
a["hello world"] = "foo";
console.log(a.length);
console.log(a["hello world"]);
Now, I don't think anyone would ever do this, but it does seem to me show weirdness in the conceptual model.
although I guess you could have someone on accident setting the value of an item in array and using a key that was NaN, example
var a = new Array();
var f = f + 3;
a[f] = "foo";
console.log(a.length);
console.log(a[f]);
I guess though it's weirdness that is easy to understand and doubtful to ever come around to bite you.