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 › Object › keys
Object.keys() - JavaScript - MDN Web Docs
Object.keys() returns an array whose elements are strings corresponding to the enumerable string-keyed property names found directly upon object. This is the same as iterating with a for...in loop, except that a for...in loop enumerates properties in the prototype chain as well.
Top answer
1 of 16
2603

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
618

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. :-)

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript - MDN Web Docs - Mozilla
February 16, 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.
🌐
Esdiscuss
esdiscuss.org › topic › maps-with-object-keys
Maps with object keys
I really don't see how to solve this other than implementing my own form of hashing for these specific objects and 'rolling my own' logic here (instead of working directly with Maps). For comparison - in Python for example I'd use a dictionary with tuple keys.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Object.keys, values, entries
Use Object.entries(obj) to get an array of key/value pairs from obj. Use array methods on that array, e.g. map, to transform these key/value pairs.
🌐
freeCodeCamp
forum.freecodecamp.org › t › problem-with-object-keys-map-in-react › 399310
Problem with Object.keys.map in React
June 5, 2020 - Hello ! I have a problem when I try to render something in React with Object.keys(Object).map. I have an object, games_list, which looks like this : games_list: { game1 : { name: "something", id: "something" }, game2 : { etc } } In my page, I’m trying to have cards with informations for each games on it (I’m using React Hooks in functional components) : return ( Your Games ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › entries
Object.entries() - JavaScript - MDN Web Docs
Each key-value pair is an array with two elements: the first element is the property key (which is always a string), and the second element is the property value. Object.entries() returns an array whose elements are arrays corresponding to the enumerable string-keyed property key-value pairs found directly upon object.
🌐
Sentry
sentry.io › sentry answers › javascript › map function for objects (instead of arrays)
Map function for objects (instead of arrays) - JavaScript
An array of the keys of the passed-in object is created using the Object.keys() method. This array is mapped over using the forEach() array method. For each value, which is a key of the obj argument, we create a key-value pair for newObject.
Find elsewhere
🌐
Medium
medium.com › @conboys111 › how-do-object-keys-object-values-and-object-entries-differ-in-javascript-8d1c19901ecb
How Do Object.keys(), Object.values(), and Object.entries() Differ in JavaScript? | by myHotTake | Medium
September 27, 2024 - Curious, I then pulled out the Object.values() map. This map was like looking at the treasures without bothering with their names. It led me down the same hallway, but now I was focused on the values behind the tags — what each treasure represented. As I walked, I noticed that even though the treasures were the same, the order they were placed followed the same rule as the key names.
🌐
Zhenghao
zhenghao.io › posts › object-vs-map
When You Should Prefer Map Over Object In JavaScript
June 18, 2022 - ES6 brings us Map. It is much more suited for a hash map use case. First of all, unlike Object, which only allows keys that are strings and symbols, Map supports keys of any data type.
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Map JavaScript Object Keys Using React | Pluralsight
September 16, 2020 - This is a naive example but it shows the power and usefulness of the built-in Object.keys method. Apart from the built-in method, it is easy to use an external library like Lodash to help you map over an object's keys. Lodash provides the _.keys method for mapping over an object's keys.
🌐
Medium
khotsufyan.medium.com › creating-a-unique-key-map-in-javascript-8968d5ada1ae
Creating Maps with unique object keys in JavaScript | by Sufyan Khot | Medium
March 7, 2023 - Creating Maps with unique object keys in JavaScript Often there are requirements where we need to create a Map which uniquely identifies buckets based on a key value. We already have this structure …
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-map-keys-method
JavaScript Map keys() Method - GeeksforGeeks
July 15, 2025 - The Map.keys() method is used to extract the keys from a given map object and return the iterator object of keys.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › get
Map.prototype.get() - JavaScript - MDN Web Docs - Mozilla
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 is held, including inside the Map.
🌐
GitHub
github.com › mmalecki › object-keys-map
GitHub - mmalecki/object-keys-map: `Array.prototype.map` for object keys
Iterates over keys of obj and creates a new object with keys based on return value of iterator and values from obj.
Author   mmalecki
🌐
DEV Community
dev.to › gustavupp › 5-reasons-to-choose-javascript-maps-over-objects-for-storing-key-value-pairswith-examples-39dd
5 Reasons To Choose JavaScript Maps Over Objects For Storing Key-Value Pairs(With Examples) - DEV Community
January 21, 2023 - Map By default, a Map does not contain any keys. It is a clean slate. It only has what you put into it. Neither more nor less. Object Objects by default have their prototype, so it contains default keys that could potentially clash with your ...
🌐
TutorialsPoint
tutorialspoint.com › object-keys-map-vs-array-map-in-javascript
Object.keys().map() VS Array.map() in JavaScript
August 18, 2020 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } </style> </head> <body> <h1>Object.keys().map() VS Array.map()</h1> <div class="sample">{1:'A',22:'B',55:'C',19:'D'}</div> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to sum the keys of the above object</h
🌐
W3Schools
w3schools.com › jsref › jsref_object_keys.asp
JavaScript Object.keys() Method
Object.entries() returns the keys and values of any object types. The methods above return an Iterable (enumerable array). Iterables makes it simpler to use objects in loops and to convert objects into maps.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript map object
The Essential Guide to JavaScript Map: How To Use Maps Effectively
October 6, 2023 - Keys and values of a Map can be any values. When iterating a Map object, each iteration returns a 2-member array of [key, value]. The iteration order follows the insertion order which corresponds to the order in which each key-value pair was ...