Access object properties and methods

Accessing the properties of an object

In JavaScript, you can use "." and "[]" to access the properties of an object.

1. Use "." to access object properties
Syntax:

objectName.propertyName


Where objectName is the object name and propertyName is the property name.

2. Use "[ ]" to access object properties
Syntax:

objectName[propertyName]


Where objectName is the object name and propertyName is the property name.

Methods to access objects

In JavaScript, you can only use "." to access methods of objects.

Syntax:

objectName.methodName()


Among them, objectName is the object name and methodName() is the function name.

Example: Create a Person class:

   


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!