const profile = { name: 'Ana', role: 'designer' };
const role = profile['role'];
console.log(role);The “role” string is used as the key, and the read value is designer.
LESSON 43 OF 50
Access a key through an expression inside brackets.
`object[expression]` turns the expression result into a key. A string such as “role” selects that named property.
const profile = { name: 'Ana', role: 'designer' };
const role = profile['role'];
console.log(role);The “role” string is used as the key, and the read value is designer.
const role = 'designer';
console.log(role);The value is hard-coded and does not demonstrate bracket access.
Store profile[“role”] in role and print the variable.
Run the code to see the result.Brackets allow the property name to be supplied as a value.
ANALYSIS REQUEST
The initial discussion is without obligation. You receive an honest recommendation, suitable stages and the factors that affect price.