猿问

在 reduce 函数中使用变量

有一种感觉,我在这里遗漏了一些明显的东西。我正在使用像这样的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中使用这些变量?


一只斗牛犬
浏览 186回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答