Changing a deeper property of an object shows in console but not when we open it or access it later.The below is my object :
 section@shikhar:
1: {displayName: "Entity", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(24), template: null, …}
2:
customTooltip: null
defaultValue: null
dependentValues: {AVS - Avionics: Array(4), DMS - Defence Mission Systems: Array(4), LAS - Land and Air Systems: Array(5), SIX - Secure Communications & Information Systems: Array(4), GTS - Ground Transportation Systems: Array(4), …}
displayName: "Business Line"
dropdownType: "SINGLESELECT"
fieldType: "DROPDOWN"
isDashboard: true
isOptional: false
isParentOf: "3"
isReporting: true
isTooltipEnabled: null
parent: 1
parentValue: ["depend"]
productTooltip: null
sequenceNumber: 2
template: null
values: []
__proto__: Object
3: {displayName: "Product Line Family", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(0), template: null, …}
4: {displayName: "Product Line", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(0), template: null, …}
5: {displayName: "Brief Instructions", dropdownType: null, fieldType: "TEXT", values: null, template: null, …}
6: {displayName: "Main message", dropdownType: null, fieldType: "TEXT", values: null, template: null, …}
7: {displayName: "Tone of voice", dropdownType: "MULTISELECT", fieldType: "DROPDOWN", values: Array(10), template: null, …}
8: {displayName: "Audience to address (Primary)", dropdownType: "MULTISELECT", fieldType: "DROPDOWN", values: Array(2), template: null, …}
9: {displayName: "Target to reach (Secondary)", dropdownType: "MULTISELECT", fieldType: "DROPDOWN", values: Array(9), template: null, …}
10: {displayName: "Sub-type", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(2), template: null, …}
11: {displayName: "Size", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(0), template: null, …}
12: {displayName: "Custom Size", dropdownType: null, fieldType: "TEXT", values: Array(0), template: null, …}
13: {displayName: "Copyrights: Expiry Date", dropdownType: null, fieldType: "DATE", values: null, template: null, …}
14: {displayName: "Output Format", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(4), template: null, …}
15: {displayName: "Other", dropdownType: null, fieldType: "TEXT", values: Array(0), template: null, …}
16: {displayName: "Tags", dropdownType: null, fieldType: "TEXT", values: null, template: null, …}
Here the problem is that even though I am setting the values inside the "2" object it still shows it as [] but actually it should have 4 values like :
{displayName: "Business Line", dropdownType: "SINGLESELECT", fieldType: "DROPDOWN", values: Array(4), template: null, …
I know the object is getting mutated somehow because even the console says that the value was evaluated just now.
The code I am using being :
 updateAllCommonValues=(val,id)=>{
    const { commonTemplateFields } = this.state;
    var commonTemplateValues = JSON.parse(JSON.stringify(commonTemplateFields));
    _.forEach(commonTemplateValues,(section,k)=>{
        _.forEach(section,(field,key)=>{
             if(key == id){
            field.value = val
                 if(field.isParentOf != null){
                    commonTemplateValues[k][Number(field.isParentOf)]['values'] = section[field.isParentOf].dependentValues[val];
                 }
            }
        })
    })
    this.setState({
        commonTemplateFields:commonTemplateValues
    },()=>{
    this.props.updateFinalPojo('orderInfo',commonTemplateValues);
    })
}
The correct value of commonTemplateFields is not coming to setstate i.e. the array for values instead it is empty as the initial state.
PS: It passes all if conditions.
PPS : Object structure :
    {  
   "values":[  
      "Flight Avionics (FLX)",
      "In-Flight Entertainment (IFE)",
      "Training & Simulation (T&S)",
      "Microwave & Imaging (MIS)"
   ],
   "parent":1,
   "parentValue":[  
      "depend"
   ],
   "dependentValues":{  
      "AVS - Avionics":[  
         "Flight Avionics (FLX)",
         "In-Flight Entertainment (IFE)",
         "Training & Simulation (T&S)",
         "Microwave & Imaging (MIS)"
      ],
      "DMS - Defence Mission Systems":[  
         "Above Water Systems (AWS)",
         "Electronic Combat Systems (ECS)",
         "Intelligence Surveillance & Reconnaissance (ISR)",
         "Under Water Systems (UWS)"
      ],
   },
   "isParentOf":"3"
}
 
    