Skip to content
Advertisement

How to use forEach method for objects in array in JavaScript?

Here is an array of donut objects.

JavaScript

Directions: Use the forEach() method to loop over the array and print out the following donut summaries using console.log.

JavaScript

I wrote this code but it doesn’t work :

JavaScript

What’s wrong?

Advertisement

Answer

Instead of

JavaScript

change it to

JavaScript

You are looping through the donuts array and calling each object a donut, but in your code, you are still trying to reference donuts.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement