Zest.

JavaScript: Loop over object keys and values

A short, tested JavaScript example for loop over object keys and values. Copy it and adjust the names and paths for your project.

JavaScript
const obj = { a: 1, b: 2 };

for (const [key, value] of Object.entries(obj)) {
  console.log(key, value);
}

Object.keys(obj);    // ["a", "b"]
Object.values(obj);  // [1, 2]

Find it in Zest

Search for “javascript loop over object keys and values” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More JavaScript examples

All JavaScript examples