LESSON 43 OF 50

Read a property with brackets

Access a key through an expression inside brackets.

Official sourceECMAScript — Property accessorsReviewed: 2026-08-26
STEP 1 · LEARN

How it works

`object[expression]` turns the expression result into a key. A string such as “role” selects that named property.

Correct example
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.

Common mistake
const role = 'designer';
console.log(role);

The value is hard-coded and does not demonstrate bracket access.

STEP 2 · APPLY

Your exercise

Store profile[“role”] in role and print the variable.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • profile contains the role property.
  • role receives profile[“role”].
  • The output is exactly designer.
Explain the solution logic

Brackets allow the property name to be supplied as a value.