Map.keys() returns a MapIterator object which can be converted to Array using Array.from:

let keys = Array.from( myMap.keys() );
// ["a", "b"]

EDIT: you can also convert iterable object to array using spread syntax

let keys =[ ...myMap.keys() ];
// ["a", "b"]
Answer from pawel on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › keys
Map.prototype.keys() - JavaScript - MDN Web Docs - Mozilla
July 20, 2025 - js · const myMap = new Map(); myMap.set("0", "foo"); myMap.set(1, "bar"); myMap.set({}, "baz"); const mapIter = myMap.keys(); console.log(mapIter.next().value); // "0" console.log(mapIter.next().value); // 1 console.log(mapIter.next().value); // {} Map.prototype.entries() Map.prototype.values() Was this page helpful to you?
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript - MDN Web Docs - Mozilla
February 16, 2026 - The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
🌐
W3Schools
w3schools.com › jsref › jsref_map_keys.asp
JavaScript Map keys() Method
JS Arrays · Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-map-keys-method
JavaScript Map keys() Method - GeeksforGeeks
July 15, 2025 - JS Tutorial · Web Tutorial · ... : 15 Jul, 2025 · The Map.keys() method is used to extract the keys from a given map object and return the iterator object of keys....
🌐
Codecademy
codecademy.com › docs › javascript › map › .keys()
JavaScript | Map | .keys() | Codecademy
October 28, 2025 - The .keys() method returns a new map iterator object containing the keys of each element in the map, respecting the insertion order.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › get
Map.prototype.get() - JavaScript - MDN Web Docs
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. const map = new Map(); map.set("bar", "foo"); console.log(map.get("bar")); // Expected output: "foo" console.log(map.get("baz")); // Expected output: undefined · js ·
🌐
Esdiscuss
esdiscuss.org › topic › maps-with-object-keys
Maps with object keys
I'm trying to work with ES6 Map objects and I ran into an interesting problem. I want to index/group based on several key values. Let's say my original data is something like: ```js [{x:3,y:5,z:3},{x:3,y:4,z:4},{x:3,y:4,z:7},{x:3,y:1,z:1},{x:3,y:5,z:4}] ``` I want to group it based on the x and y property values, so I want the result to look something like: ```js {x:3,y:5} ==> {x:3,y:5,z:3},{x:3,y:5,z:4} {x:3,y:4} ==> {x:3,y:4,z:4},{x:3,y:4,z:7} {x:3,y:1} ==> {x:3,y:1,z:1} ``` However, as the docs and draft say maps detect existence ( `Map.prototype.has ( key )`) for object the same way `===` works for objects (specified in `SameValueZero(x, y)`).
Find elsewhere
🌐
Justin Fagnani
justinfagnani.com › 2024 › 11 › 09 › composite-map-keys-in-javascript-with-bitsets
Composite Map Keys in JavaScript with Bitsets
November 9, 2024 - Nested Maps work by doing successive lookups with your keys, like map.get(o1)?.get(o2). The problem is that you need a lot of Map instances. You're building a tree of maps, so there can be reuse due to branching, but at the limit, for a set of key size of K objects and N keys you need up to N * (K - 1) Maps.
Top answer
1 of 6
39

This is not a Map object. It's just a regular object. So, use Object.entries and then use map on the key value pair:

const map = {"a": 1, "b": 2, "c": 3};
const mapped = Object.entries(map).map(([k,v]) => `${k}_${v}`);
console.log(mapped);

Object.entries returns:

[["a",1],["b",2],["c",3]]

Then loop through each of those inner arrays and create the string using template literals


If you have a Map object, use Array.from(map) to get the entries of the map and use the second parameter of Array.from to go over each entry and create the desired string

Array.from(map, ([k,v]) => `${k}_${v}`)
2 of 6
16

It's not a map, it's an object. (You might consider using a Map, though.)

To get its properties as key/value pairs, you can use Object.entries, which you can then apply map to:

map = Object.entries(map).map(([key, value]) => key + "_" + value);

Object.entries is relatively new, but easily polyfilled for older environments.

Live Example:

var map = {"a": 1, "b": 2, "c": 3};
map = Object.entries(map).map(([key, value]) => key + "_" + value);
console.log(map);


Or, using a Map, you can use its built-in entries method, which returns an iterable, passing it into Array.from and using Array.from's mapping callback:

var map = new Map([
  ["a", 1],
  ["b", 2],
  ["c", 3]
]);
map = Array.from(map.entries(), ([key, value]) => key + "_" + value);
console.log(map);

(Or expand the iterable into an array — [...map.entries()] — and use map on it, but the above avoids a temporary throw-away array.)

In both cases, I'm using destructuring in the parameter list of the arrow function, which receives an array in [key, value] format.

🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Map and Set
Map – is a collection of keyed values. ... new Map([iterable]) – creates the map, with optional iterable (e.g.
🌐
W3Schools
w3schools.com › js › js_maps.asp
JavaScript Maps
JS Examples JS HTML DOM JS HTML ... JS Bootcamp JS Certificate JS Reference ... A JavaScript Map is an object that can store collections of key-value pairs, similar to a dictionary in other programming languages....
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript map keys method
JavaScript - Map.keys() Method
September 1, 2008 - In JavaScript, the Map.keys() method does not accept any parameters and returns a new iterator object that contains the keys for each element present in the Map object, in insertion order.
🌐
Google
developers.google.com › google maps platform › web › maps javascript api › set up the maps javascript api
Set up the Maps JavaScript API | Google for Developers
To create an API key, navigate to the Google Maps Platform Credentials page and select \"Create credentials \\\u003e API key.\" Restricting API keys to specific applications and APIs is strongly recommended for security and to prevent financial ...
🌐
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 - For example, Java has the well known HashMap, which stores data in buckets, and each bucket is located by the value of its key. Maps in JavaScript are a bit different. Although they were created to make it convenient for us to store objects as keys, there is a problem.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › map
Mastering JS
May 29, 2019 - Here's how you can use date-fns-tz to work with timezones, and alternatives for working with timezones in vanilla JS.
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. :-)