Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Read a Property

Fundamentals: Part 2easy

Course · Section 3: JavaScript Fundamentals – Part 2 · Lecture 44: Dot vs. Bracket Notation

Implement `getProp(obj, key)` returning the value at `key` using bracket notation.

Sample tests

Input: getProp({"a":1,"b":2}, "b")
Output: 2
Input: getProp({"x":5}, "x")
Output: 5

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Dot notation cannot use a key held in a variable.
Visualize this concept: Truthy and Falsy Values →
Approach & explanation (try first)

Bracket notation reads the property named by the key variable.

Loading...
⌘/Ctrl + Enter

Run your code to see results.