What is an Object in JavaScript and How to Access Properties



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: 2019-07-30T22:30:26+05:30

111 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements