Articles → JavaScript → JavaScript object literal

JavaScript object literal






Definition





Syntax


{Key1:value1, key2:value2}



Example


var test = {Name:'Karan', Address:'India'}



How to access values?




var test = {Name:'Karan', Address:'India'}
alert(test.Name);
alert(test.Address);



Types of values












var test = {
    			Name:'Karan', 
    			Age:32, 
                Books:['Book1','Book2'],
                Height:{feet:5, inch:4},
                Click :function(){alert('click me')}
};
                
alert(test.Name);
alert(test.Age);
alert(test.Books[0]);
alert(test.Books[1]);
alert(test.Height.feet);
alert(test.Height.inch);
test.Click();


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, May 01, 2018

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250