What are the properties of an array object in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type.

The following is the list of the properties of the Array object −

Sr.No
Property & Description
1
constructor
Returns a reference to the array function that created the object.
2
index
The property represents the zero-based index of the match in the string.
3
input
This property is only present in arrays created by regular expression matches.
4
length
Reflects the number of elements in an array.
5
prototype
The prototype property allows you to add properties and methods to an object.

Example

Let’s see an example of the prototype property

Live Demo

<html>    
   <head>      
      <title>JavaScript Array Object</title>              
      <script>          
         function book(title, author){            
            this.title = title;              
            this.author  = author;          
         }      
      </script>          
   </head>    
   <body>              
      <script>          
         var myBook = new book("Java", "John");
         book.prototype.price = null;          
         myBook.price = 300;                    
         document.write("Book title is : " + myBook.title + "<br>");          
         document.write("Book author is : " + myBook.author + "<br>");          
         document.write("Book price is : " + myBook.price + "<br>");      
      </script>        
   </body>
</html>

Output

Book title is : Java
Book author is : John
Book price is : 300
raja
Published on 18-Feb-2018 05:58:48
Advertisements