What is an object in JavaScript and access any property ?**


Accessing Property Of An Object

Without objects there is no JavaScript. Everything such as boolean,numbers,functions etc are all objects.Accessing properties of an object is explained in the following method.

Example-1

 Live Demo

<html>
<body>
<script>
   myObj = {"name":"Ramesh","age":30,"family":
           [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
           var res = myObj.family[0].mother;
  document.write(res);
</script>
</body>
</html>

Output

Geetha

Example-2

 Live Demo

<html>
<body>
<script>
   myObj = {"name":"Ramesh","age":30,"family":
           [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
   var res = myObj.city;
   document.write(res);
</script>
</body>
</html>

Output

Berlin

Updated on: 30-Jul-2019

86 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements