I have an array of objects like this:
const rates = [{
price: 20,
time_periods: [
{
period: "1 Week",
rate: 5,
},
{
period: "2 Months",
rate: 9,
},
],
}, {...}]
It will then be converted into a table with all cells editable. I have a callback that tells me which cell was exactly edited. It returns 3 values: a value from input, number of row (array index in our case), and name of the column (key of the object)
I save it to my array like that: rates[index][key] = value
The problem is that I can get values like this: 20, 2, time_periods[0].rate
, which causes the above line doesn't work. It works with eval like this: eval(`rates[${index}].${key}`)
but I heard that using eval is not the best idea.
Is there any other way to deal with this? I could try to change the structure of my array to be less complicated but yeah, wanted to know if I can achieve my goal without doing it.