有一种感觉,我在这里遗漏了一些明显的东西。我正在使用像这样的reduce函数
const obj = this.data.reduce((ac,{Category, Count}) => (ac[Category] = Count,ac),{});
但是,我现在需要使用变量将 Category 和 Count 设为动态。因此,我已经完成了
const cat = this.format.header[0];
const count = this.format.header[1];
const obj = this.data.reduce((ac,{cat, count}) => (ac[cat] = count,ac),{});
这似乎并没有使用我的变量。我也尝试在其中使用它,但这也不起作用。
如何在reduce中使用这些变量?
相关分类