Below is the example of the Array constructor property.
- Example:
<!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_rightfilter_none - 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:
< 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:
< 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
- Internet Explorer
- Mozila Firefox
- Safari
- Opera