当我尝试使用javascript console打印日志时,我有一个动态生成的数组,其中包含每个部分的字符串数据。log(res)显示如下:
[{Activity: "Change Request", Total:"4427" },{ Activity: "Design Escallation", Total:"1067"}]
这是我的代码:
this.projectservice.getEventActivity().subscribe((res)=>{
console.log(res);
})
有什么方法可以将我的res转换并解析成这样的格式:
[["Change Request", 4427],["Design Escallation", 1067]]
感谢支持人员...
答案 0 :(得分:0)
您可以使用map和destructuring assignment
let data = [{Activity: "Change Request", Total:"4427" },{ Activity: "Design Escallation", Total:"1067"}]
let op = data.map(({ Activity, Total}) => [Activity,Total])
console.log(op)
答案 1 :(得分:0)
this.projectservice.getEventActivity().subscribe((res)=>{
this.result=res.map(({Activity,Total})=> [Activity,Total])
console.log(this.result)})
在不弄乱的情况下,这将起作用!