Wednesday, 10 May 2017

How to get Map as an object in javascript ES6?

My Class is using es6 to create an map object at node level, using Map()--"set" function.When class is called i want the map object to get converted to normal json type structure. I am using moongoose to retreive the data from database.

res.json(MapObject);

After using this res.json whole content inside parent node is getting empty.

{success:{},
 error:{},
redirectMe:false}

Have Map Object like this

{
  success: 
   Map {
     'String1' => 'true',
     'Object1' => [ [Object],
                    [Object],
                    [Object],
                    [Object],
                    [Object]
                  ]
     'String2' => 100 
     }
  error: Map {},
  redirectMe: false 
}

I want to get result as an Object but when I tries to get it not able to get anything

Wanted something like

{
  success: 
    {
     'String1' : 'true',
     'Object1' : [ [Object],
                    [Object],
                    [Object],
                    [Object],
                    [Object]
                  ]
     'String2' : 100 
     }
  error: {},
  redirectMe: false 
}



via Kunal Vashist

No comments:

Post a Comment