Hello, how can I updated nested child value in Object -> example Variable is 2 & Item VariableGroup is 2 so new value will be 999 instead of 160.
It should also work for changing others in case helperFunction is called example (1,1,55).
var data = [
{
"Variable": 1,
"Item": [
{
"VariableGroup": 1,
"VariableValue": 190
},
{
"VariableGroup": 2,
"VariableValue": 38
}
]
},
{
"Variable": 2,
"Item": [
{
"VariableGroup": 1,
"VariableValue": 80
},
{
"VariableGroup": 2,
"VariableValue": 160
}
]
},
{
"Variable": 3,
"Item": [
{
"VariableGroup": 1,
"VariableValue": 900
},
{
"VariableGroup": 2,
"VariableValue": 1200
}
]
},
]
function helperFx (variable: number, variablegroup: number, variablevalue: number)
{
let newdata = [...data];
for(let item of newdata){
if (item.Variable === variable)
{
for(let v of item.Item )
{
if(v.VariableGroup === variablegroup)
{
console.log(v);
break;
}
}
}
}
};
helperFx(2,2,999);