
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Accessing JavaScript Object Properties: How Many Ways?
An object property can be accessed in two ways. One is .property and the other is [property].
Syntax-1
Object.property;
Syntax-2
Object["property"];
For better understanding, lets' look at the following example.
In the following example an object called 'person' is defined and its properties were accessed in a dot notation.
Example
<html> <body> <script> var person = { firstname:"Ram", lastname:"kumar", age:50, designation:"content developer" }; document.write(person.firstname + " " + "is in a role of" + " " + person.designation); </script> </body> </html>
Output
Ram is in a role of content developer
In the following example the properties of an object 'person' were accessed in bracket notation.
Example
<html> <body> <script> var person = { firstname:"Ram", lastname:"kumar", age:50, designation:"content developer" }; document.write(person['firstname']+ " " + "is in a role of" + " " + person['designation']); </script> </body> </html>
Output
Ram is in a role of content developer
Advertisements