I want to convert an es6 nested Map to an object.
I tried this code:
mapToObjectRec(m) { let lo = {} for(let[k,v] of m) { if(v instanceof Map) { lo[k] = this.mapToObjectRec(v) } else { lo[k] = v } } return lo } I want to do the opposite of this function:
export declare type IElementsMap = Map<string, IElements>; deserializeElements(json: any): IElementsMaps | any { const elementsMap = new Map<string, IElementsMap>(); if (Array.isArray(json)) { json.forEach(outer => { const elementMap = new Map<string, IElements>(); outer[1].forEach(inner => { elementMap.set(inner[0], inner[1]); }); elementsMap.set(outer[0], elementMap); }); return elementsMap; } return json; } I want to send converted data inside payload request (Post request).
json.forEach(...)makes you thinkjsonis an array, but JSON is always a string. If your variable is an array of elements, name itelemsor something.