有一種感覺,我在這里遺漏了一些明顯的東西。我正在使用像這樣的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中使用這些變量?
在 reduce 函數中使用變量
一只斗牛犬
2021-06-15 17:23:35