How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 06-02-object-entries-to-get-iterable.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js with a function named main that creates an object then uses a for-of loop to loop over the result of Object.entries:
// main.js 
export function main() { 
  const object = { 
    foo: Math.random(), 
    bar: Math.random() 
  }; 
  for (let [prop, value] of Object.entries(object)) { 
    console.log(prop, value); 
  } 
} 
  1. Start your Python web server and open the following link in your browser:  http://localhost:8000/.
  1. You will see the following output:

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.