

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- How many ways a String object can be created in java?
- In how many ways can we split a string in JavaScript?
- In how many ways can we find a substring inside a string in javascript?
- Explain the different ways in which data from a series data structure can be accessed in Python?
- 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?
- In how many ways you can retrieve the elements of a collection in Java?
- JavaScript - Determine all possible ways a group of values can be removed from a sequence
- In how many ways we can convert a String to a character array using Java?
- How many ways to iterate a TreeSet in Java?
- How many ways to iterate a LinkedList in Java?
- Program to check how many ways we can choose empty cells of a matrix in python
- How to remove a property from a JavaScript object
- How to remove a property from a JavaScript object?
- In how many ways we can concatenate Strings in Java?
Advertisements