Home » JavaScript

Array constructor property with example in JavaScript

JavaScript array constructor property: Here, we are going to learn about the constructor property of array in JavaScript.
Submitted by IncludeHelp, on February 27, 2019

JavaScript constructor property

constructor property is used to get details of the array's constructor function, it returns the reference to the function.

Syntax:

    array_name.constructor;

Examples:

    Input:
    var arr1 = [10, 20, 30, 40, 50];

    Function call:
    arr1.constructor;
    
    Output:
    function Array() { [native code] }

JavaScript Code to get the constructor details

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		var arr1 = [10, 20, 30, 40, 50];
		var arr2 = ["Amit", "Ankur", "Akash"];
		var arr3 = [];
		
		document.write("Constructor of arr1: " + arr1.constructor + "<br>");
		document.write("Constructor of arr2: " + arr2.constructor + "<br>");
		document.write("Constructor of arr3: " + arr3.constructor + "<br>");
	</script>
</body>
</html>

Output

Constructor of arr1: function Array() { [native code] }
Constructor of arr2: function Array() { [native code] }
Constructor of arr3: function Array() { [native code] }





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.