Could someone explain this block of code to me and what the type of ‘arr’ is.
I know that an array is an object but
- Why does the [[Class]] show up as Array if it behaves like an Object
-
arr.length returns 3. How?
var arr = [0, 1, 3]; arr.name = "asdf"; console.log(arr[1] + " " + arr.name + " " + arr.length); // Returns-> 1 asdf 3 Object.prototype.toString.call(arr); // Returns-> "[object Array]"
Whats the deal here?
This has already been answered in good detail in this SO post
JavaScript arrays are specialized objects, so they are both arrays and objects. So you can add properties to them like any other object. Only numeric properties are taken into account for the
lengthproperty so adding arbitrary properties likenamewill not affect it.