

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Objects
incomplete
2: No Colon
incomplete
3: Updating Properties
incomplete
4: Nesting Properties
incomplete
5: Nesting Properties Quiz
incomplete
6: Optional Chaining
incomplete
7: When to Chain
incomplete
8: Object Methods
incomplete
9: Methods Mutate
incomplete
10: Initializing Props
incomplete
11: Strings As Keys
incomplete
12: This
incomplete
13: Arrow Functions
incomplete
14: Fat Arrows and This
incomplete
15: Spread Syntax
incomplete
16: Return Objects
incomplete
17: Destructuring
incomplete
18: Not Bound
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Accessing a property like desk.height is great when the name of the prop is static, meaning you know what it is before runtime. But what if the key is dynamic? Like, what if the user enters a string and you need to use that as the lookup key?
Bracket notation solves this.
const desk = {
wood: "maple",
width: 100,
};
console.log(desk.wood);
// prints "maple"
console.log(desk["wood"]);
// also prints "maple"
const key = "wood";
console.log(desk[key]);
// also prints "maple"
For example, maybe the key is passed in as a parameter to a function:
function getLastName(lastNames, firstName) {
return lastNames[firstName];
}
Complete the getProviderCount function. It takes two parameters:
provider (string): The name of the cellular provider (e.g., 'Verizon', 'AT&T').counts (object): An object where each key is a provider name, and the value is the number of phone numbers associated with that provider.The function should return the count of phone numbers for the given provider. If the provider doesn't exist in the counts object, return 0.