beginner
Find Object Property
Access and return a specific property from an object.
Learn object property access with dot and bracket notation.
📚 Concepts & Theory
Object Access
obj.name // dot notation
obj['name'] // bracket notation 🎯 Your Challenge
Write getProperty that returns the value of a property.
📝 Starter Code
JavaScript
function getProperty(obj, key) {
// Your code here
}
console.log(getProperty({name: 'John', age: 30}, 'name'));
Solution
JavaScript
function getProperty(obj, key) {
return obj[key];
}
console.log(getProperty({name: 'John', age: 30}, 'name'));
Explanation
Use bracket notation for dynamic keys.
❓ Frequently Asked Questions
Bracket for dynamic keys