I have a for loop which is supposed to loop twice. I want to use the incremented values (1 and 2) to set id. However, it gives me value 3 in both cases.
Here is my code:
for(var i=1; i<=2; i++) { //Add two options by default
this.setState(prevState => ({ //add option Object with default attributes
options_array: [...prevState.options_array, { id: i,
description: '',
value: null }],
}))
}