Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

map to array javascript

let map = new Map().set('a', 1).set('b', 2),
    array = Array.from(map, ([name, value]) => ({ name, value }));

console.log(array);
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

map to array javascript

let map = new Map().set('a', 1).set('b', 2),
    array = Array.from(map, ([name, value]) => ({ name, value }));

console.log(array);
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 :: transitionduration js 
Javascript :: check change event in jquery 
Javascript :: join text in js 
Javascript :: debug react vscode 
Javascript :: get child routes using parent in angular 
Javascript :: free robux javascript 
Javascript :: javascript add hours 
Javascript :: angular input value 
Javascript :: livewire file upload progress 
Javascript :: react make component full screen 
Javascript :: define array with custom index javascript 
Javascript :: navigating programatically react 
Javascript :: material ui align icon with text 
Javascript :: js replace all symbols in string 
Javascript :: onclick open link js 
Javascript :: how to get all form values in javascript 
Javascript :: write bytes64 in json python 
Javascript :: javascript set width percentage update 
Javascript :: bootstrap js, jQuery, popper cdn 
Javascript :: read all file names of folder in react 
Javascript :: redux persist a non-serializable value was detected in an action in the path register 
Javascript :: js get object properties 
Javascript :: javascript math pi 
Javascript :: yarn build react 
Javascript :: .textcontent 
Javascript :: js localstorage 
Javascript :: javascript truncate array 
Javascript :: download file javascript 
Javascript :: jquery detect change in textarea content 
Javascript :: hello world using alert 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =