have a feeling I am missing something obvious here. I was using a reduce function like so
const obj = this.data.reduce((ac,{Category, Count}) => (ac[Category] = Count,ac),{});
However, I now need Category and Count to be dynamic, using a variable. As such, I have done
const cat = this.format.header[0];
const count = this.format.header[1];
const obj = this.data.reduce((ac,{cat, count}) => (ac[cat] = count,ac),{});
This does not seem to be using my variables though. I have also tried using this within it, but this also does not work.
How can I use these variables within the reduce?
Thanks
thisandthis.data? Also, why don't you just use an arrow function with curly braces then define your variables inside of that?