- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How many ways can a property of a JavaScript object be accessed?
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
To Continue Learning Please Login
Login with Google