Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert map to object/JSON javascript

const map1 = new Map([
  ['foo', 'bar'],
  ['baz', 42]
]);

const obj = Object.fromEntries(map1);
// { foo: 'bar', baz: 42 }

//To get back the map:
const map2 = new Map(Object.entries(obj));
Comment

convert map to json js, map to json

const mapToJson = (map) => JSON.stringify(Object.fromEntries(map));
const map = new Map([
  ['user1', 'John'],
  ['user2', 'Kate'],
  ['user3', 'Peter'],
]);
const json = mapToJson(map);
// {"user1":"John","user2":"Kate","user3":"Peter"}
console.log(json);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check if two keys are pressed 
Javascript :: how to import background image in inline css in react 
Javascript :: nodejs format text 
Javascript :: react delete button onclick 
Javascript :: get youtube id from url javascript 
Javascript :: phaser 3 add button 
Javascript :: duplicate an array in javascript n times 
Javascript :: javascript how to raise the error 
Javascript :: vue fetch api 
Javascript :: javascript key pressed enter 
Javascript :: how to append rows in table using jquery each function 
Javascript :: replace string using javascript 
Javascript :: sort from the key value js 
Javascript :: How to convert data to utf-8 in node.js 
Javascript :: javascript get child element by class 
Javascript :: wait for element to load 
Javascript :: clear input field react-hook-form 
Javascript :: get child routes using parent in angular 
Javascript :: require express 
Javascript :: relode div 
Javascript :: react js materilize 
Javascript :: buffer from base64 
Javascript :: boucle for javascript 
Javascript :: Capitalise a String 
Javascript :: remove key from object array javascript 
Javascript :: angular checkbox disabled 
Javascript :: cypress click link contains text 
Javascript :: difference between == and === in javascript 
Javascript :: how to update kali linux on virtualbox 
Javascript :: javascript get ip 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =