Related Articles

Related Articles

JavaScript Array constructor Property
  • Last Updated : 23 Jun, 2020

Below is the example of the Array constructor property.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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>    

    chevron_right

    
    

  • 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:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

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

  • Google Chrome
  • Internet Explorer
  • Mozila Firefox
  • Safari
  • Opera

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :