Another way to access properties of an object is by using the bracket notation. The bracket notation allows us to access properties dynamically, using variables or expressions as property names.
Here is an example:
In this example, we have defined a variable
propertyName and assigned it the value of
'name'. We can then use the bracket notation to access the
name property of the
person object by passing
propertyName within the brackets.
propertyName variable and use it inside the bracket notation to access the corresponding property value.
student object, use bracket notation to access and console log the value of the
Create a variable called
property and set it equal to
property variable and bracket notation to access and console log the value of the
grade property. (
Sign up to start coding
Already have an account?