Use Object.keys() -

let data = [{"facebook":"https://facebook.com"}, {"instagram":"https://instagram.com"}]

data.forEach(social => console.log(Object.keys(social)[0]));

Here, I'm using .forEach() instead of .map() just to log the key's name, but the idea is the same with .map().

Answer from Dust_In_The_Wind on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript - MDN Web Docs - Mozilla
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.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-array-of-objects-to-map
How to convert an Array to a Map in JavaScript | bobbyhadz
March 4, 2024 - Pass the array of the key-value pairs to the Map() constructor. ... Copied!const arr = [ {key: 'name', value: 'bobby hadz'}, {key: 'country', value: 'Chile'}, ]; const map1 = new Map( arr.map(obj => { return [obj.key, obj.value]; }), ); // ...
Discussions

javascript - How do I get the key in array of objects using .map()? - Stack Overflow
You can use Object.keys with map ... an array of it's own properties. So Object.keys(item)[0] will give the key from each object. var social = [{ "facebook": "https://facebook.com" }, { "instagram": "https://instagram.com" }] var x = social.map(function(item) { return Object.keys(item)[0] }) console.log(x) ... Find the answer to your question by ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Mapping Array Of Objects By Key - Stack Overflow
I have two arrays created from a reduce method that searches two existing arrays for dates. It then turns those dates into unique object keys. The first group is a list of names the second is a set... More on stackoverflow.com
🌐 stackoverflow.com
November 26, 2020
javascript - How to map an array of objects to an array of values by key - Stack Overflow
:) OP seems to be new to JavaScript, and still making their first steps. Don't rush into ES6 yet. 2016-10-13T05:40:35.997Z+00:00 ... @Adam Azad Thanks you so much, Adam! But I am just confusing what does the obj mean here? 2016-10-13T05:45:37.757Z+00:00 ... @XiufenXu, obj is the object like{ _id: 123, message: 'hello', username: '1' } for instance. It's a mere variable referring to the current object in the array... More on stackoverflow.com
🌐 stackoverflow.com
javascript - 'map' function for objects (instead of arrays) - Stack Overflow
The reason that this works is due to the .map functions returning an array REQUIRING that you provide an explicit or implicit RETURN of an array instead of simply modifying an existing object. You essentially trick the program into thinking the object is an array by using Object.keys which will ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › map
Array.prototype.map() - JavaScript - MDN Web Docs
July 12, 2026 - The map() method reads the length property of this and then accesses each property whose key is a nonnegative integer less than length. ... const arrayLike = { length: 3, 0: 2, 1: 3, 2: 4, 3: 5, // ignored by map() since length is 3 }; console.log(Array.prototype.map.call(arrayLike, (x) => ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-an-array-of-objects-to-a-map-in-javascript
How to Convert an Array of Objects to Map in JavaScript? - GeeksforGeeks
July 23, 2025 - JavaScript · const a = [ { id: ... and works well for simple transformations. The reduce() method allows you to iteratively build a Map by accumulating key-value pairs....
🌐
W3Schools
w3schools.com › jsref › jsref_map.asp
JavaScript Array map() Method
Dot [ ] Bracket [ ] Array Literal { } Block { } Object Literal ?. Chaining ... Spread ( ) Grouping ( ) ? x : y Ternary ( ) Invocation => Arrow delete in instanceof typeof void yield yield* JS Precedence ... 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 BigInt
Find elsewhere
🌐
Medium
medium.com › codingbeauty-tutorials › javascript-convert-array-to-map-12907a8a334a
How to Convert an Array to a Map in JavaScript | Coding Beauty Tutorials
September 18, 2024 - To convert an array of objects to a map, we can use the Array map() method to create an array of key-value pairs, and then pass the resulting array to a Map() constructor to create a Map object.
🌐
DigitalOcean
digitalocean.com › community › tutorials › 4-uses-of-javascripts-arraymap-you-should-know
How to Use the JavaScript .map() Method | DigitalOcean
Learn how to use the JavaScript .map() method to transform arrays with clear examples, syntax explanations, and practical use cases.
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. :-)

🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › map array to object
Map a JavaScript array to an object - 30 seconds of code
January 15, 2024 - The result of the mapping function ... to map an array of objects to an object. This is done by mapping each object to a key and value, via a pair of mapping functions....
🌐
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 - The Object.fromEntries() method is then used to convert this array of key-value pairs into an object: 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)
🌐
Hackr
hackr.io › home › articles › programming
Beginner’s Guide to JavaScript Map Array | Array Map() Method
January 30, 2025 - JavaScript Maps are iterables with a key-value pair constructor that looks like a 2D array, but acts like an Object. They offer better flexibility than Objects for keys as they can be any data-type.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Map and Set
... new Map([iterable]) – creates the map, with optional iterable (e.g. array) of [key,value] pairs for initialization. map.set(key, value) – stores the value by the key, returns the map itself.
🌐
Attacomsian
attacomsian.com › blog › javascript-convert-array-of-objects-to-map
Convert an array of objects to a Map in JavaScript
June 7, 2023 - Subsequently, you can pass this array of key-value pairs to the Map() constructor to create a Map object. const users = [ { name: 'John Doe', role: 'Admin' }, { name: 'Alex Hales', role: 'Manager' }, { name: 'Ali Feroz', role: 'User' } ] const ...
Top answer
1 of 4
7

You could take the first key of the objects.

myArr1.map((key, value) => Object.keys(key)[0]);

function getData() {
    const result = Object
            .keys(myJSON.countries)
            .map(k => myJSON.countries[k])
            .map(({ currencies }) => currencies)
            .map(currency => Object.keys(currency)[0]);

    console.log(result);
}

var myJSON = { countryCode: { Australia: "AU", "United States": "US", Britain: "GB", Japan: "JP", India: "IND", France: "FR", Russia: "RS" }, countries: { AE: { currencies: { AED: { isDefault: true } } }, AL: { currencies: { ALL: { isDefault: true } } }, AU: { currencies: { AUD: { isDefault: true } } }, US: { currencies: { USD: { isDefault: true } } }, GB: { currencies: { EUR: { isDefault: true } } }, FR: { currencies: { EUR: { isDefault: true } } }, JP: { currencies: { JPY: { isDefault: true } } }, RS: { currencies: { RSD: { isDefault: false } } }, ZA: { currencies: { ZAR: { isDefault: true } } } } };
	
<button onclick="getData()">Get Data</button>

Or just in a single step:

function getData() {
    const result = Object
            .keys(myJSON.countries)
            .map(k => Object.keys(myJSON.countries[k].currencies)[0]);

    console.log(result);
}

var myJSON = { countryCode: { Australia: "AU", "United States": "US", Britain: "GB", Japan: "JP", India: "IND", France: "FR", Russia: "RS" }, countries: { AE: { currencies: { AED: { isDefault: true } } }, AL: { currencies: { ALL: { isDefault: true } } }, AU: { currencies: { AUD: { isDefault: true } } }, US: { currencies: { USD: { isDefault: true } } }, GB: { currencies: { EUR: { isDefault: true } } }, FR: { currencies: { EUR: { isDefault: true } } }, JP: { currencies: { JPY: { isDefault: true } } }, RS: { currencies: { RSD: { isDefault: false } } }, ZA: { currencies: { ZAR: { isDefault: true } } } } };
	
<button onclick="getData()">Get Data</button>

2 of 4
2

You can use map & for..in loop to iterate over the object

var myJSON = {
  "countryCode": {
    "Australia": "AU",
    "United States": "US",
    "Britain": "GB",
    "Japan": "JP",
    "India": "IND",
    "France": "FR",
    "Russia": "RS"
  },
  "countries": {
    "AE": {
      "currencies": {
        "AED": {
          "isDefault": true
        }
      }
    },
    "AL": {
      "currencies": {
        "ALL": {
          "isDefault": true
        }
      }
    },
    "AU": {
      "currencies": {
        "AUD": {
          "isDefault": true
        }
      }
    },
    "US": {
      "currencies": {
        "USD": {
          "isDefault": true
        }
      }
    },
    "GB": {
      "currencies": {
        "EUR": {
          "isDefault": true
        }
      }
    },
    "FR": {
      "currencies": {
        "EUR": {
          "isDefault": true
        }
      }
    },
    "JP": {
      "currencies": {
        "JPY": {
          "isDefault": true
        }
      }
    },
    "RS": {
      "currencies": {
        "RSD": {
          "isDefault": false
        }
      }
    },
    "ZA": {
      "currencies": {
        "ZAR": {
          "isDefault": true
        }
      }
    }
  }
};

function getData() {
  // get countries object
  let getCountries = myJSON.countries;
  // get all country short names in an array
  var ctr = Object.keys(getCountries);
  // iterate that array using map 
  var getCur = ctr.map(function(item) {
    // in countries object get the object where the country shortname
    // matches the object key. Get the curriencies usin for ..in loop
    for (let keys in getCountries[item].currencies) {
      return keys
    }
  })
  console.log(getCur)
}
<button onclick="getData()">Get Data</button>

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-a-map-to-array-of-objects-in-javascript
How to convert a map to array of objects in JavaScript? - GeeksforGeeks
July 23, 2025 - The Array.from() method of JavaScript can be used to convert a map into an array of objects by passing the map and a callback function with the names of object keys as parameters to it.