Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript converting an array into a map

const arr = ['a', 'b', 'c', 2, 3, 4];
const nwMap = new Map([...arr.entries()]); 
Comment

array to map js

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

var result = new Map(arr.map(i => [i.key, i.val]));

// When using TypeScript, need to specify type:
// var result = arr.map((i): [string, string] => [i.key, i.val])

// Unfortunately maps don't stringify well.  This is the contents in array form.
console.log("Result is: " + JSON.stringify([...result])); 
// Map {"foo" => "bar", "hello" => "world"}
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: mac os chrome opne debug new tab 
Javascript :: render react component 
Javascript :: convert json to array 
Javascript :: javascript change css opacity duration 
Javascript :: jQuery Effects - Fading 
Javascript :: javascript change video poster 
Javascript :: Regex Chords 
Javascript :: sort by date javascript 
Javascript :: http header express 
Javascript :: sequelize.fn 
Javascript :: jquery global variable 
Javascript :: react native margin vs padding 
Javascript :: express session 
Javascript :: nevigate on button click in angular 
Javascript :: Connect to socket.io node.js command line 
Javascript :: export component react 
Javascript :: match 
Javascript :: react hide element 
Javascript :: encrypt in js 
Javascript :: live search javascript 
Javascript :: some method javascript 
Javascript :: js remove last char of string 
Javascript :: angular convert map values to array 
Javascript :: js basic user class 
Javascript :: Add Image For React Native 
Javascript :: react style css image 
Javascript :: javascript get magnitude of number 
Javascript :: react cdn 
Javascript :: javascript base64 to length 
Javascript :: dynamic button click in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =