This will output:
obj.a = 1
obj.b = 2
obj.c = 3
Another approach is to use the
Object.keys() method in combination with
Array.prototype.forEach(). This allows us to loop over the keys of an object, and then access each value inside the loop.
This will output the same result as the
for...in loop example above.
Object.entries() method returns an array of an object's own enumerable string-keyed property [key, value] pairs. This can be useful for looping over objects in a more functional manner.
This will also output the same result as the previous examples.
Join our community of forward-thinkers and innovators. Subscribe to get the latest updates on courses, exclusive insights, and tips from industry experts directly to your inbox.