I have my form field values in an immutable object.
I use getIn immutable function to access it.
For example, if I have to access field, i use const users = formFields.getIn(['0', value]).
Now, i have a variable
users = 4`
This means, there will be 4 fields in immutable from which i need to pick up the users age.
e.g.
- 1st user age will be stored in
formFields.getIn(['1', value]) - 2nd user age will be stored in
formFields.getIn(['2', value]) - and so on
How do i loop through the user age list based on the users variable?
I tried something like this:
const userAgeList = [];
if (users >0) {
userAgeList.push(formFields.getIn([[i], value]));
}
With above code formFields.getIn([[i], value]), i get undefined because the value is not actually on this. its on formFields.getIn(['i', value]).
How do i pass the loop variable i as a string so i can get the field values?
[i]this makes an array with one value, the value ofi. Is this what you're expecting?formFields.getIn([`${i}`, value])??formFields.getIn([i.toString(), value])?