- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Articles
- How many ways a String object can be created in java?
- In how many ways can we split a string in JavaScript?
- Explain the different ways in which data from a series data structure can be accessed in Python?
- In how many ways can we find a substring inside a string in javascript?
- Can private methods of a class be accessed from outside of a class in Java?
- How many ways can get the instance of a Class class in Java?
- JavaScript - Determine all possible ways a group of values can be removed from a sequence
- In how many ways you can retrieve the elements of a collection in Java?
- How to remove a property from a JavaScript object?
- How do we remove a property from a JavaScript object? - JavaScript
- How to delete a property of an object in JavaScript?
- How to get the list of document properties which can be accessed using W3C DOM?
- In how many ways we can convert a String to a character array using Java?
- How do I remove a property from a JavaScript object?
- Can a local variable's memory be accessed outside its scope in C/C++?

Advertisements