This is fairly trivial to do with Array.prototype.reduce:

var arr = [
    { key: 'foo', val: 'bar' },
    { key: 'hello', val: 'world' }
];

var result = arr.reduce(function(map, obj) {
    map[obj.key] = obj.val;
    return map;
}, {});

console.log(result);
// { foo:'bar', hello:'world' }

Note: Array.prototype.reduce() is IE9+, so if you need to support older browsers you will need to polyfill it.

Answer from jmar777 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
To convert an ordinary object that's not iterable or array-like to an array (by enumerating its property keys, values, or both), use Object.keys(), Object.values(), or Object.entries(). To convert an async iterable to an array, use Array.fromAsync(). Array.from() never creates a sparse array.
Discussions

javascript - How to convert Map to array of object? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. ... Save this answer. ... Show activity on this post. You could take Array.from and map the key/value pairs. More on stackoverflow.com
🌐 stackoverflow.com
Functional Programming - Use the map Method to Extract Data from an Array
Hi all, thanks for taking the time to look at my question 🙂 I’m having a bit of trouble understanding this function in the example, so i understand that the map function will iterate over users to extract the results i want. But what i dont understand is (user => user.name), why dont we ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
3
0
March 24, 2023
Array turning into a Map-like object and some other questions
The MDN docs on Map do a pretty good job of spelling this out, particularly the Objets vs. Maps section. Technically you're using an array in your example, but arrays are just objects with some additional functionality so its basically the same thing. More on reddit.com
🌐 r/learnjavascript
10
2
December 22, 2023
Spread operator not working when doing array.map on an array of objects?
It's the syntax of your callback. Change it to a.map(item => ({ ...item, someBool: true})) More on reddit.com
🌐 r/learnjavascript
3
3
October 13, 2022
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map
Map - JavaScript | MDN
August 13, 2026 - A Map object is iterated by key-value pairs — a for...of loop returns a 2-member array of [key, value] for each iteration. Iteration happens in insertion order, which corresponds to the order in which each key-value pair was first inserted into the map by the set() method (that is, there wasn't a key with the same value already in the map when set() was called).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › map
Array.prototype.map() - JavaScript | MDN
July 12, 2026 - The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array. const array = [1, 4, 9, 16]; // Pass a function to map const mapped = array.map((x) => x * 2); console.log(mapped); // Expected output: Array ...
🌐
W3Schools
w3schools.com › jsref › jsref_map.asp
JavaScript Array map() Method
Return a new array with the square root of all element values.
Find elsewhere
🌐
CoreUI
coreui.io › blog › how-to-convert-a-map-to-an-array-in-javascript
How to Convert a Map to an Array in JavaScript · CoreUI
May 22, 2024 - Converting a Map to an array in JavaScript can be done using various methods such as Array.from(), the spread operator, and manual iteration. Each method offers flexibility depending on whether you need the keys, values, or both.
🌐
Mimo
mimo.org › glossary › javascript › map
JavaScript Map Function: Examples for Data Transformation
The .map() method creates a new array by calling a provided function on every element in the original array. It takes each element, transforms it according to the function, and adds the result to the new array. The original array remains unchanged. ... Become a full-stack developer.
🌐
Robin Wieruch
robinwieruch.de › javascript-map-array
Deep Dive into JavaScript's Array Map Method - Robin Wieruch
March 6, 2019 - An extensive walkthrough for JavaScript developers who want to get to know the Array's Map Method to transform data. You will learn about the Callback Function's Arguments, usages of Map with other Array Methods, and ...
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Map and Set
Why? How can we fix the code to make keys.push work? solution · That’s because map.keys() returns an iterable, but not an array.
🌐
Amydegregorio
amydegregorio.com › 2021 › 04 › 14 › using-javascript-map-to-map-an-array-of-primitives-to-one-of-objects
Using JavaScript map() to Map an Array of Primitives to One of Objects – Amy's Programming Corner
April 15, 2021 - In JavaScript, the Array.map() method is often used to map a list of objects into a more simple array comprised of the values from particular field in all the objects. The other day, I had a need to expand an array of strings, into an array ...
🌐
R0b
blog.r0b.io › post › quick-concise-array-to-map-conversion-in-javascript
Quick Array to Map Conversion in JavaScript | r0b blog
February 28, 2021 - Each item is an array where the first subitem is the key and the second is a value. When passed to the Map constructor, the key will be the index to lookup by and the value is the thing to lookup.
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › convert-map-to-array-of-object
Converting a Map to Array of Objects: A Step-by-Step Guide
JavaScript · October 17, 2023 ... 1 }, { name: 'key2', value: 2 } ] Explanation: Here, the Array.from method is used to convert a map to an array of arrays....
🌐
Medium
medium.com › @SoraEagle › javascript-the-map-array-method-c5bcdc6d9cb3
Javascript: The .map() Array Method | by Matthew Phillips | Medium
November 10, 2021 - But, does the .map() actually transform the array it is used on? NO. In reality, the .map() method actually does something different. Actually, .map() creates a copy of the original array, and allows you to transform it.
🌐
Programiz
programiz.com › javascript › library › array › map
JavaScript Array map()
thisArg (optional) - Value to use as this when executing callback. By default, it is undefined. Returns a new array with elements as the return values from the callback function for each element. ... let newPrices = prices.map(Math.sqrt); // [ 42.42640687119285, 44.721359549995796, 54.772255750516614, // 70.71067811865476, 22.360679774997898, 89.44271909999159 ] console.log(newPrices); // custom arrow function const string = "JavaScript"; const stringArr = string.split(''); // array with individual string character
🌐
Code Beautify
codebeautify.org › blog › map-to-array-javascript
Map to Array in Javascript
May 5, 2023 - The “Array.from()” method in JavaScript is a static function that helps to a new array object from an array-like or iterable object. It can be used to convert various types of data or object into an array, such as a string, a NodeList, or a Set.
🌐
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.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Functional Programming - Use the map Method to Extract Data from an Array - Curriculum Help - The freeCodeCamp Forum
March 24, 2023 - Hi all, thanks for taking the time to look at my question :slight_smile: I’m having a bit of trouble understanding this function in the example, so i understand that the map function will iterate over users to extract t…
🌐
CodingBat
codingbat.com › java
CodingBat Java
Welcome to Codingbat. See help for the latest. Java Example Solution Code · Java String Introduction (video) Java Substring v2 (video) Java String Equals and Loops · Java String indexOf and Parsing · Java If and Boolean Logic · If Boolean Logic Example Solution Code 1 (video) If Boolean Logic Example Solution Code 2 (video) Java For and While Loops · Java Arrays and Loops · Java Map Introduction ·
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
You will often want to display multiple similar components from a collection of data. You can use the JavaScript array methods to manipulate an array of data. On this page, you’ll use filter() and map() with React to filter and transform your array of data into an array of components.