Do arrays have no prototype by default?-Collection of common programming errors
prototype
is a property of constructor functions, like Array
. So Array.prototype
exists, but not [1, 2, 3].prototype
; Array
is a constructor function, while [1, 2, 3]
is an array.
You are looking for Object.getPrototypeOf([1, 2, 3])
.
Object.getPrototypeOf
is an ECMAScript 5 method, and as such may not be present in all browsers. In which case, you can try accessing the __proto__
property, i.e. [1, 2, 3].__proto__
, which is an older, nonstandard thing that Object.getPrototypeOf
is the new standard version of, or you can use an ES5 shim to ensure that wherever __proto__
is supported, so is Object.getPrototypeOf
.
Originally posted 2013-11-10 00:11:23.