JavaScript constructor Property
Example
Return the function that created the prototype of the fruits array object:
fruits.constructor;
Result output:
function Array() { [native code] }
Try it »
Definition and Usage
In JavaScript, the constructor property returns the constructor function of an object.
The return value is a reference to the function, not the function name:
The JavaScript Array constructor property returns ** function Array() { [native code] }**
The JavaScript Number constructor property returns ** function Number() { [native code] }**
The JavaScript String constructor property returns ** function String() { [native code] }**
If a variable is an array you can use the constructor property to identify it.
Browser support
| property | |||||
|---|---|---|---|---|---|
| constructor | Yes | Yes | Yes | Yes | Yes |
All major browsers support the constructor property.
Syntax
array
.constructor
Technical Details
| Return Value: | A function object. This function is the one originally used to create the array object. |
|---|---|
| JavaScript version: | 1.1 |
JavaScript Array object