DEV Community


Posted on

How to iterate over object properties?

There’s an object.
The object contains key value pairs.
To iterate over properties we need the Object.entries method.
The Object.entries method returns an array of key value pairs.
We need the forEach method to iterate over the array.
And we need the array destructuring assignment to get the key and the value.

const props = {
    cx: 200,
    cy: 100,
    r: 50

Object.entries(props).forEach(([key, value]) => {
    console.log(key, value);
Enter fullscreen mode Exit fullscreen mode

Let’s check it out.
There’s all the properties.
One by one.

I hope you found this article useful, if you need any help please let me know in the comment section.

👋 See you next time. Have a nice day!

Subscribe to our channel:

Discussion (0)