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
    • 107
    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.


    <html>
    
        <script type="text/javascript">
            /* Declare Object*/     
            var detail = new object();
            /* initialize the array */
    
            detail.firstname = 'naveen';
            detail.lastname = 'kumar';
            detail.email = 'xxx@hotmail.com';
    
            detail.getFullDetail = function(){
                alert(detail.firstname+ ' '+ detail.lastname + ' '+ detail.email);  
            }
    
            detail.getFullDetail();
        </script>   
    
    
    </html>
    


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


    <html>
    
        <script type="text/javascript">
            /* Declare Object*/     
            var detail = {
            'firstname':'naveen',
            'lastname':'kumar',
            'email':'xxx@hotmail.com',
            'getFullDetail' = function(){
                alert(this.firstname+ ' '+ this.lastname + ' '+ this.email);    
            }
    
            detail.getFullDetail();
        </script>   
    
    
    </html>
    


    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: