In my React application, I am trying to update columns depending on what the date is. Essentially, if it's the first week, my variable would be 1. The second week, my variable would be 2. Etc. In Airtable, I have several columns with the same name, but they each end with a different number (which would be the variable). I have created a variable concatenating the column name (with no number on the end) with the week number variable. I'm running a loop that is creating buttons based off data in AirTable, and onClick I want to set a variable = to the column name + week number variable. My problem is that the line of code that accesses the column in AirTable requires you to write the literal name of the column, it won't allow me to insert a variable to access the field.
I have tried just inserting the variable name. I have tried surrounding my variable in brackets and braces.
let weekNumber = "W"+this.props.weekNumberValue for (let i = 0; i < this.state.courses.length; i++){
buttonDataList.push(<button key={i} onClick={() =>
{this.setState({courseDayNum:
this.state.courses[i].fields.weekNumber})}}> My Button
</button> )
}
The code as is unable to write to pull data from AirTable because I don't have a column named "weekNumber". If I type {weekNumber} or [weekNumber] instead of weekNumber , ReactJS recognizes the variable value but returns "Parsing error: Unexpected token" .