How to access properties of an array of objects in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To access properties of an array of objects, you can try to run the following code −

Example

Live Demo

<html>  
   <head>      
      <title>User-defined objects</title>              
      <script>          
         function book(title, author){            
            this.title = title;              
            this.author  = author;          
         }      
      </script>          
   </head>    
   <body>              
      <script>          
         var myBook = new book("PHP", "Amit");          
         book.prototype.price = null;          
         myBook.price = 250;                    
         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 : PHP
Book author is : Amit
Book price is : 250
raja
Published on 18-Feb-2018 06:10:21
Advertisements