Skip to content
Related Articles

Related Articles

JavaScript Array constructor Property

Improve Article
Save Article
Like Article
  • Last Updated : 01 Oct, 2021

Below is the example of the Array constructor property. 
 

  • Example: 
     

html




<!DOCTYPE html>
<html>
    <head>
        <title>
            JavaScript Array constructor Property
        </title>
    </head>
 
    <body style="text-align: center;">
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
 
        <b>JavaScript | Array constructor Property</b>
        <br>
        <button onclick="myGeeks()">
            Submit
        </button>
 
        <p id="sudo"></p>
 
 
 
        <!-- Script for array constructor -->
        <script>
            function myGeeks() {
                var name = ["sahil", "Manas",
                            "Sagar", "Harshit"];
                document.getElementById("sudo").innerHTML =
                  name.constructor;
            }
        </script>
    </body>
</html>   
  • Output:

The JavaScript Array constructor property is used to return the constructor function for an array object. It only returns the reference of the function and not returns the name of the function. So, In JavaScript arrays, it returns the function Array() { [native code] }.
Syntax: 
 

array.constructor

Return value: It returns the function reference i.e. function Array() { [native code] }.
More example codes for the above property are as follows: 
Program 1: 
 

html




<script type = "text/javascript">
        var arr = new Array( "Geeks", "for", "Geeks");
        document.write("arr.constructor:" + arr.constructor);
</script>   

Output: 
 

arr.constructor:function Array() { [native code] }

Program 2: 
 

html




<script type = "text/javascript">
        var arr = new Array( 5, 10, 15);
        document.write("arr.constructor:" + arr.constructor);
</script>   

Output: 
 

arr.constructor:function Array() { [native code] }

Supported Browsers: The browsers supported by JavaScript Array constructor Property are listed below: 
 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 4 and above
  • Safari 1 and above

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!