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 PropertySee 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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/javascript/object-property-method/array-constructor.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics