使用map,动态添加对象属性名,属性值
// 将map转为对象
function MapchangeToObj(strMap: any) {
let obj = {};
for (let [key, val] of strMap) {
obj[key] = val;
}
return obj;
}
let arrmap: any = new Map();
arrmap.set('test', 123);
MapchangeToObj.(arrmap) // { test:123 }

浙公网安备 33010602011771号