JavaScript:- object

What is a JavaScript object?


  • Objects also a type of variable. But objects can contain many values.
  • The values are written as name : valuepairs (name and value separated by a colon).
  • The named values, in JavaScript objects, are called properties.

  • Code:-

  • <!DOCTYPE html> 
    <html> 

    <head> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
    </head> 

    <body> 

     <input type="button" value="Know about object" onclick="cal_fun();"> 

     <div id="d1"></div> 
     <div id="d2"></div> 
     <script> 
      function cal_fun() 
      { 
       var schhis = { 
        school: "St,joseph's HSSS", 
        place: "Mulagumoodu", 
        year: "1984" 
       }; 
       var student = { 
        stu1: 
        { 
         name1: "Merbin", 
         place: "Mulagumoodu" 
        }, 
        stu2: 
        { 
         name2: "Franklin", 
         place: "Marthandam" 
        }, 
        stu3: 
        { 
         name3: "Ramesh", 
         place: "Trivandrum" 
        } 
       } 

       document.getElementById('d1').innerHTML = "School Name : " + schhis.school + "School Place : " + schhis.place + " Year : " + schhis.year; 

       document.getElementById('d2').innerHTML = "Name 1 : " + student.stu1.name1 + "place : " + student.stu1.place; 

      } 
     </script> 

    </body> 

    </html>
  • JavaScript:- object JavaScript:- object Reviewed by Network security on June 03, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.