Object Keys Iteration in JavaScript
Level 3134 keystrokes
Object.keys() returns an array of property names, allowing iteration over objects.
JavaScript code
// Create an object with subject scores1const scores = { math: 90, english: 85, science: 95 };// Object.keys() returns ["math", "english", "science"]// forEach iterates through each key2Object.keys(scores).forEach(key => { // Access the value using bracket notation // Template literal formats the output3 console.log(`${key}: ${scores[key]}`);4});Output
math: 90 english: 85 science: 95
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
:× 4{× 4}× 4;× 3.× 3(× 3)× 3,× 2`× 2=× 2