JAVASCRIPT / OBJECTS · STEP 1 OF 3
Read object values through changing keys
Checking your account…
GUIDED PRACTICE
Read object values through changing keys
Follow the current step, write the requested code and choose Run & check this step. Your own program carries forward.
Your code stays in one editor through every step. Word wrap is enabled.
Step 1 of 3
Start with one named key
Brackets can use a variable containing a property name. This is the access pattern a for-in loop will need.
Your task
In script.js, make the changes in the checklist. Keep the working code from earlier steps.
To pass this step:
- Declare
const selectedKey = "name";. - Print
learner[selectedKey]. Expect Maya.
Press the play button labeled Run & check this step below the editor to run your code and see your check results.
Your editor is opening.
Each step builds on the last. Finish the current step before opening the next one; your code stays with you.
This is one possible solution. Compare it with your own code; opening it does not replace your work or complete a step.
const learner = { name: "Maya", city: "Miami" };
const selectedKey = "name";
console.log(learner[selectedKey]);const learner = { name: "Maya", city: "Miami" };
const selectedKey = "name";
console.log(learner[selectedKey]);
for (const key in learner) {
if (Object.hasOwn(learner, key)) {
console.log(key + ": " + learner[key]);
}
}const learner = { name: "Maya", city: "Miami" };
const selectedKey = "name";
console.log(learner[selectedKey]);
for (const key in learner) {
if (Object.hasOwn(learner, key)) {
console.log(key + ": " + learner[key]);
}
}
console.log(learner.city.toLowerCase());Code and completed steps save in this browser when signed out. Sign in to save across devices.
Choose the copy to continue. Your account work will only be replaced if you choose this device.
Ready to checkRun the checks to see your results here.