The conversion to and from JSON
Let’s use this knowledge to convert any Map with JSON-compatible data to JSON and back:
function mapToJson(map) {
return JSON.stringify([...map]);
}
function jsonToMap(jsonStr) {
return new Map(JSON.parse(jsonStr));
}
浙公网安备 33010602011771号