Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Declaring Objects in javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 124
    Comment on it


    Objects are another powerful way of handling and storing of data. In arrays the indexes are commonly numerical; objects give us a better way of assigning and retrieving data.


    1. <html>
    2.  
    3. <script type="text/javascript">
    4. /* Declare Object*/
    5. var detail = new object();
    6. /* initialize the array */
    7.  
    8. detail.firstname = 'naveen';
    9. detail.lastname = 'kumar';
    10. detail.email = 'xxx@hotmail.com';
    11.  
    12. detail.getFullDetail = function(){
    13. alert(detail.firstname+ ' '+ detail.lastname + ' '+ detail.email);
    14. }
    15.  
    16. detail.getFullDetail();
    17. </script>
    18.  
    19.  
    20. </html>


    Another way of creating an object is by using the curly braces.


    1. <html>
    2.  
    3. <script type="text/javascript">
    4. /* Declare Object*/
    5. var detail = {
    6. 'firstname':'naveen',
    7. 'lastname':'kumar',
    8. 'email':'xxx@hotmail.com',
    9. 'getFullDetail' = function(){
    10. alert(this.firstname+ ' '+ this.lastname + ' '+ this.email);
    11. }
    12.  
    13. detail.getFullDetail();
    14. </script>
    15.  
    16.  
    17. </html>


    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: