[This is first question on SO, so apologize me for any mistake]
I'm trying to save a Map, like the one below, in a cookie.
var myMap = new Map();
myMap.set("k1", {
a1: "...",
a2: "...",
a3: "..."
});
For this, I have to format as JSON. I tried many methods, like:
$.toJSON(myMap)
$.param(myMap)
JSON.stringify(myMap)
But none of them seems to work...
So, I did this:
var serial = [];
myMap.forEach(function(value){
serial.push(value);
});
var result = $.toJSON(serial)
(Having to reconstruct the key on decoding the JSON...)
There is a better way to serialize a Map object?