How To Convert Map Keys to an Array in JavaScript? Last Updated : 05 Aug, 2025 Comments Improve Suggest changes Like Article Like Report Here are the various methods to convert Map keys to an array in JavaScript1. Using array.from() MethodThe Array.from() method in JavaScript converts Map keys to an array by using 'Array.from(map.keys())'. JavaScript let map = new Map().set('GFG', 1).set('Geeks', 2); let a = Array.from(map.keys()); console.log(a.length); Output2 In this exampleA Map object is created with two key-value pairs: ‘GFG’ => 1 and ‘Geeks’ => 2.Map.keys() returns an iterator for the keys of the Map (‘GFG’, ‘Geeks’).Array.from(Map.keys()) converts the iterator into an array of keys: ['GFG', 'Geeks'].2. Using for...of Loop MethodThe for...of loop method converts Map keys to an array by iterating over map.keys(). Within the loop, each key is pushed into a new array. JavaScript let map = new Map().set('GFG', 1) .set('Geeks', 2).set('Geeksforgeeks', 3); let a = []; for (let key of map.keys()) { a.push(key); } console.log(a); Output[ 'GFG', 'Geeks', 'Geeksforgeeks' ] In this exampleA Map object is created with three key-value pairs: 'GFG' => 1, 'Geeks' => 2, and 'Geeksforgeeks' => 3.The for...of loop iterates over the keys of the Map and pushes each key ('GFG', 'Geeks','Geeksforgeeks') into the array.3. Using Object.keys() and Object.fromEntries()The Object.keys() and Object.fromEntries() methods in JavaScript convert Map keys to an array by first transforming the Map into an object with Object.fromEntries(map), then using Object.keys() to extract the keys from this object into an array. JavaScript const map = new Map([ ["JS", 1], ["Ruby", 2], ["C++", 3] ]); let obj = Object.fromEntries(map); let key = Object.keys(obj); console.log(key); Output[ 'JS', 'Ruby', 'C++' ] In this exampleA Map object is created with key-value pairs: "JS" => 1, "Ruby" => 2, and "C++" => 3.Object.fromEntries(map) converts the Map to an object, resulting in { JS: 1, Ruby: 2, C++: 3 }.Object.keys(obj) extracts the keys from the object, returning an array ['JS', 'Ruby', 'C++'], which is logged to the console.4. Using the Spread Operator (...)Another convenient way to convert the keys of a Map to an array is by using the spread operator(...). JavaScript const map = new Map([["JS", 1], ["Ruby", 2], ["C++", 3]]); const key = [...map.keys()]; console.log(key); Output[ 'JS', 'Ruby', 'C++' ] In this examplemap.keys() returns an iterator object.The spread operator (...) expands the iterator into individual elements and creates an array. Comment More info P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like