Avatar ·

How to iterate over all object properties in JavaScript? Iteration over keys and values

Hello everyone! I just started learning JavaScript and ran into a problem. I have an object with user data:\n\n```javascript\nconst users = {\n user1: { name: 'Anna', age: 25 },\n user2: { name: 'Ivan', age: 30 },\n user3: { name: 'Maria', age: 28 }\n};\n```\n\nI need to output each user's name and age to the console. I tried using a regular `for` loop, but it doesn't work with objects — it returns `undefined`. I googled it and found something about `for...in`, but I didn't understand how to use it correctly. I also saw mentions of `Object.keys()`, `Object.values()`, and `Object.entries()` methods, but I got confused about the differences between them and which one is better.\n\nPlease tell me how to properly iterate over all object properties? Preferably with code examples so it's clear for a beginner.