How to Convert an Object to a Map in JavaScript

 

What is an object an object can be a variable, a data structure, a function, or a method or a representative of a class that can hold properties and variables.

 

Use the Object.entries() method to get an array of key value pair

 

let javaObject = {
					one: 1, 
					two: 2, 
					three: 3, 
					four: 4, 
					five: 5
				};
				
let nawMap = new Map(Object.entries(javaObject));	

// covert object to JSON string
let jsonString = JSON.stringify(javaObject);

Tags:

Share:

Related posts