There is no native map to the Object object, but how about this:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

Object.keys(myObject).forEach(function(key, index) {
  myObject[key] *= 2;
});

console.log(myObject);
// => { 'a': 2, 'b': 4, 'c': 6 }

But you could easily iterate over an object using for ... in:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

for (var key in myObject) {
  if (myObject.hasOwnProperty(key)) {
    myObject[key] *= 2;
  }
}

console.log(myObject);
// { 'a': 2, 'b': 4, 'c': 6 }

Update

A lot of people are mentioning that the previous methods do not return a new object, but rather operate on the object itself. For that matter I wanted to add another solution that returns a new object and leaves the original object as it is:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

// returns a new object with the values at each key mapped using mapFn(value)
function objectMap(object, mapFn) {
  return Object.keys(object).reduce(function(result, key) {
    result[key] = mapFn(object[key])
    return result
  }, {})
}

var newObject = objectMap(myObject, function(value) {
  return value * 2
})

console.log(newObject);
// => { 'a': 2, 'b': 4, 'c': 6 }

console.log(myObject);
// => { 'a': 1, 'b': 2, 'c': 3 }

Array.prototype.reduce reduces an array to a single value by somewhat merging the previous value with the current. The chain is initialized by an empty object {}. On every iteration a new key of myObject is added with twice the key as the value.

Update

With new ES6 features, there is a more elegant way to express objectMap.

const objectMap = (obj, fn) =>
  Object.fromEntries(
    Object.entries(obj).map(
      ([k, v], i) => [k, fn(v, k, i)]
    )
  )
  
const myObject = { a: 1, b: 2, c: 3 }

console.log(objectMap(myObject, v => 2 * v)) 

Answer from Amberlamps on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript | MDN
August 13, 2026 - Map objects are collections of key-value pairs. A key in the Map may only occur once; it is unique in the Map's collection. A Map object is iterated by key-value pairs — a for...of loop returns a 2-member array of [key, value] for each iteration.
🌐
W3Schools
w3schools.com › js › js_maps.asp
JavaScript Maps
A JavaScript Map is an object that can store collections of key-value pairs, similar to a dictionary in other programming languages.
Top answer
1 of 16
2605

There is no native map to the Object object, but how about this:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

Object.keys(myObject).forEach(function(key, index) {
  myObject[key] *= 2;
});

console.log(myObject);
// => { 'a': 2, 'b': 4, 'c': 6 }

But you could easily iterate over an object using for ... in:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

for (var key in myObject) {
  if (myObject.hasOwnProperty(key)) {
    myObject[key] *= 2;
  }
}

console.log(myObject);
// { 'a': 2, 'b': 4, 'c': 6 }

Update

A lot of people are mentioning that the previous methods do not return a new object, but rather operate on the object itself. For that matter I wanted to add another solution that returns a new object and leaves the original object as it is:

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

// returns a new object with the values at each key mapped using mapFn(value)
function objectMap(object, mapFn) {
  return Object.keys(object).reduce(function(result, key) {
    result[key] = mapFn(object[key])
    return result
  }, {})
}

var newObject = objectMap(myObject, function(value) {
  return value * 2
})

console.log(newObject);
// => { 'a': 2, 'b': 4, 'c': 6 }

console.log(myObject);
// => { 'a': 1, 'b': 2, 'c': 3 }

Array.prototype.reduce reduces an array to a single value by somewhat merging the previous value with the current. The chain is initialized by an empty object {}. On every iteration a new key of myObject is added with twice the key as the value.

Update

With new ES6 features, there is a more elegant way to express objectMap.

const objectMap = (obj, fn) =>
  Object.fromEntries(
    Object.entries(obj).map(
      ([k, v], i) => [k, fn(v, k, i)]
    )
  )
  
const myObject = { a: 1, b: 2, c: 3 }

console.log(objectMap(myObject, v => 2 * v)) 

2 of 16
619

How about a one-liner in JS ES10 / ES2019 ?

Making use of Object.entries() and Object.fromEntries():

let newObj = Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, v * v]));

The same thing written as a function:

function objMap(obj, func) {
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, func(v)]));
}

// To square each value you can call it like this:
let mappedObj = objMap(obj, (x) => x * x);

This function uses recursion to square nested objects as well:

function objMap(obj, func) {
  return Object.fromEntries(
    Object.entries(obj).map(([k, v]) => 
      [k, v === Object(v) ? objMap(v, func) : func(v)]
    )
  );
}

// To square each value you can call it like this:
let mappedObj = objMap(obj, (x) => x * x);

With ES7 / ES2016 you can't use Objects.fromEntries, but you can achieve the same using Object.assign in combination with spread operators and computed key names syntax:

let newObj = Object.assign({}, ...Object.entries(obj).map(([k, v]) => ({[k]: v * v})));

ES6 / ES2015 Doesn't allow Object.entries, but you could use Object.keys instead:

let newObj = Object.assign({}, ...Object.keys(obj).map(k => ({[k]: obj[k] * obj[k]})));

ES6 also introduced for...of loops, which allow a more imperative style:

let newObj = {}

for (let [k, v] of Object.entries(obj)) {
  newObj[k] = v * v;
}


array.reduce()

Instead of Object.fromEntries and Object.assign you can also use reduce for this:

let newObj = Object.entries(obj).reduce((p, [k, v]) => ({ ...p, [k]: v * v }), {});


Inherited properties and the prototype chain:

In some rare situation you may need to map a class-like object which holds properties of an inherited object on its prototype-chain. In such cases Object.keys() and Object.entries() won't work, because these functions do not include the prototype chain.

If you need to map inherited properties, you can use for (key in myObj) {...}.

Here is an example of such situation:

const obj1 = { 'a': 1, 'b': 2, 'c': 3}
const obj2 = Object.create(obj1);  // One of multiple ways to inherit an object in JS.

// Here you see how the properties of obj1 sit on the 'prototype' of obj2
console.log(obj2)  // Prints: obj2.__proto__ = { 'a': 1, 'b': 2, 'c': 3}

console.log(Object.keys(obj2));  // Prints: an empty Array.
console.log(Object.entries(obj2));  // Prints: an empty Array.

for (let key in obj2) {
  console.log(key);              // Prints: 'a', 'b', 'c'
}

However, please do me a favor and avoid inheritance. :-)

🌐
Telerik
telerik.com › blogs › javascript-map-object
The JavaScript Map Object
January 18, 2024 - It’s worth noting that if you only need string keys and simple key-value operations, JavaScript objects can still be a suitable choice. Map objects in JavaScript provide a powerful and flexible way to store and manipulate key-value pairs.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › map
Array.prototype.map() - JavaScript | MDN
July 12, 2026 - const numbers = [1, 4, 9]; const roots = numbers.map((num) => Math.sqrt(num)); // roots is now [1, 2, 3] // numbers is still [1, 4, 9] The following code takes an array of objects and creates a new array containing the newly reformatted objects.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › get
Map.prototype.get() - JavaScript | MDN
The get() method of Map instances returns the value corresponding to the key in this Map, or undefined if there is none. Object values are returned as the same reference that was originally stored, not as a copy, so mutations to the returned object will be reflected anywhere that reference ...
🌐
Sentry
sentry.io › sentry answers › javascript › map function for objects (instead of arrays)
JavaScript Map Function for Objects Instead of Arrays | Sentry
April 15, 2023 - function mapFn(value) { return value * 2; } function objectMap(obj, fn) { return Object.fromEntries( Object.entries(obj).map(([key, value]) => [key, fn(value)]) ); } console.log(objectMap(myObject, mapFn)); // { a: 4, b: 8, c: 12 } Youtube How Sentry.io saved me from disaster (opens in a new tab) Resources Improve Web Browser Performance - Find the JavaScript code causing slowdowns (opens in a new tab)
🌐
Syncfusion
syncfusion.com › blogs › javascript › javascript map vs. object
JavaScript Map vs. Object | Syncfusion Blogs
December 19, 2024 - However, minor variations make Map work better under specific conditions, mainly because Object do not preserve the insertion order of elements when storing the data. A Map can be created using the Map constructor in JavaScript.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-map
Map in JS - GeeksforGeeks
A JavaScript Map holds key-value pairs and similar to Hash Map or Dictionary in other languages. Preserves the original insertion order. Supports any type, including objects and primitives, as keys or values.
Published: July 1, 2026
🌐
Esdiscuss
esdiscuss.org › topic › maps-with-object-keys
Maps with object keys
I'm working on several projects that perform statistical analysis and I wanted to stick to JavaScript, this makes it really hard to do so. It effectively renders `Map`s useless for me exept for readability purposes. Also, thanks for the straight up 'this is still a problem now' - it probably saved me a considerable amount of time. Value types do sound like a better solution than throwing `equals` and `hash` on every object, it is conceptually similar to the solution I've got so far (using a flyweight to enforce uniqueness and generate 'value objects').
🌐
freeCodeCamp
freecodecamp.org › news › javascript-map-and-set-objects-explained
How to Use the JavaScript Map and Set Objects – Explained with Code Examples
February 21, 2024 - It can use any type of data as the key value, while an object can only use string values as keys. Under the hood, the Map object performs better when you need to add and remove keys, so you might consider using it when your data changes frequently.
🌐
Medium
medium.com › @conboys111 › when-to-use-a-map-instead-of-an-object-in-javascript-e396f1b27b19
When to Use a Map Instead of an Object in JavaScript | by myHotTake | Medium
January 1, 2025 - Map: Optimized for key-value storage, making it faster and more consistent for these operations. Use Objects for small, simple cases where keys are strings or you need a plain data structure. ... Need keys of different types (objects, symbols, etc.). Care about performance for a lot of additions/removals. Need reliable iteration order for keys. So, in JavaScript, choosing between an Object and a Map is like choosing the right locker system for the job — Objects work fine for basic needs, but Maps shine when things get complex or performance matters!
🌐
Zhenghao
zhenghao.io › posts › object-vs-map
When You Should Prefer Map Over Object In JavaScript
June 18, 2022 - In JavaScript, objects are handy. They allow us to easily group multiple pieces of data together. After ES6, we got a new addition to the language - Map. In a lot of aspects, it seems like a more capable Object with a somewhat clumsy interface. However, most people still reach for objects when they need a hash map and only switch to using Map when they realize the keys can't just be strings for their use cases.
🌐
DEV Community
dev.to › mlgvla › javascript-using-the-map-object-322e
JavaScript: Using the Map Object - DEV Community
March 1, 2022 - The Map object in JavaScript bears a strong resemblance to the standard Object that uses key/value pairs.
🌐
LinkedIn
linkedin.com › learning › javascript-maps-and-sets › the-map-object-defined
The Map object defined - JavaScript Video Tutorial
This course provides a detailed guide to JavaScript maps and sets, exploring common use cases and surprises they hold.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › Map
Map() constructor - JavaScript | MDN
Note: Map() can only be constructed with new. Attempting to call it without new throws a TypeError. ... If an iterable object (such as an array) is passed, all of its elements will be added to the new Map. Each element must be an object with two properties: 0 and 1, which correspond to the key and value (for example, [[1, "one"],[2, "two"]]).
🌐
Scaler
scaler.com › home › topics › javascript map vs object
JavaScript Map vs Object - Scaler Topics
December 16, 2022 - Map is a data structure, storing data in the form of key-value pairs, which contains a unique key and value mapped to the key. Furthermore, no duplicate pair is retained due to the uniqueness of each key that is kept. ... An object in Javascript is also a data structure following the key-value ...