Avatar ·

Map function for objects in JavaScript (analog of Array.prototype.map)

Hello everyone! I've been writing JavaScript for a few months now, and I've run into a problem. I know that arrays have a great `.map()` method that allows you to transform each element and get a new array. For example: ```javascript const numbers = [1, 2, 3]; const doubled = numbers.map(n => n * 2); // doubled = [2, 4, 6] ``` But what if I need to do the same thing with an object? I have an object with user data: ```javascript const users = { alice: { age: 25, city: 'Moscow' }, bob: { age: 30, city: 'SPb' }, charlie: { age: 35, city: 'Kazan' } }; ``` I want to get a new object where each user gets a field `isAdult: true`, because everyone is over 18. But objects don't have a `.map()` method! I tried using `Object.key