The Dynamic Gate
Medium+20 XP
Mission Briefing
The Chamber of Secrets changes its password mechanism daily! Today, the required access key is hidden inside an encrypted variable. You cannot hardcode dot notation here!
The Concept: Dynamic Keys / Bracket Notation
When the exact property name you want is stored inside a variable, dot notation (obj.key) will literally look for a property named "key"! To evaluate the variable dynamically, you must use bracket notation: obj[variable].
The Objective
Your function receives an object obj and a string variable key.
- Use bracket notation to look up the property in
objdefined bykey. - Return that specific value.
01EXAMPLE 1
Input
obj = { power: 9000 }, key = "power"Output
9000Constraints
- You must use bracket notation obj[key].
FundamentalsObjects
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
obj{"name":"JS"}
key"name"
Expected Output
JS
Click RUN to test your solution