w3resource

JavaScript constructor Property: Array Object

Description

The constructor property of the array object specifies the function that creates an object's prototype.

Version

Implemented in JavaScript 1.1

Syntax

object.constructor

Object: The name of the object (Required).

Example:

In the following web document, the constructor property returns the reference to the function that creates the object.

HTML Code

<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>JavaScript Array constructor Property</title>
<meta name="description" content="This document contains an example of JavaScript Array constructor Property" />
<style type="text/css">
h1{color: red;}
</style>
</head>
<body>
<h1>JavaScript Array constructor Property</h1>
<script src="array-constructor-example1.js"></script>
</body>
</html>

JS Code

var myarray = new Array("Orange", "Apple", "Banana", "Cherry", "Mango");
var newParagraph = document.createElement("p"); //creates a new paragraph element
var newText = document.createTextNode("The object is constructed from : "+myarray.constructor); //creates text along with ouput to be displayed 
newParagraph.appendChild(newText); //created text is appended to the paragraph element created
document.body.appendChild(newParagraph); // created paragraph and text along with output is appended to the document body

View the example in the browser

Practice the example above online

JavaScript Array constructor Property

See also :

JavaScript Core objects, methods, properties.

Previous: Javascript Array Objects - Properties and Methods
Next: JavaScript index Property: Array Object

Test your Programming skills with w3resource's quiz.



JavaScript: Tips of the Day

Returns true if the given number is a power of 2, false otherwise

Example:

const tips_isPowerOfTwo = n => !!n && (n & (n - 1)) == 0;
console.log(tips_isPowerOfTwo(0)); 
console.log(tips_isPowerOfTwo(4));
console.log(tips_isPowerOfTwo(16));

Output:

false
true
true