Here is an object of 3 forms formA, formB, formC in which form A and B are objects and formC is an array of objects which can have multiple objects
const object: {
"formA": {
"details": {},
"isRouteUser": false,
"province": "ON",
"prelabel": 10,
"users": [
{
"age": 0
}
]
},
"formB": {
"line11": 0,
"line12": 0,
"line150_1": 0
},
"formC": [
{
"price": 0,
"details": [
{
"subItemPrice": 0
}
]
}
]
}
I am using the function to find the value of the fields inside the forms
const getValue = (object, keys) => keys.split('.').reduce((o, k) => (o || {})[k], object);
const key1 = formB.line11
const key2 = formC[0].price
const key3 = formC[0].details[0].subItemPrice
I am using this function to get the value
const formValue = getValue(object,key1)
case 1: key 1 worked well
case 2: key2 - works on the selected index it should work for every index of the array
case 3: key3 - failed