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




  1. Any data type
  2. Array
  3. Function
  4. Nested key-value pair
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 1, 2018

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250