Constructing object array using dynamic keys in react/Javscript

I tried to contrcut the object based on response coming from API.

my key is assigned this.RootKeyValue and my response is assigned to this.keyResponse

this.RootKeyValue is the key of parent of first object .

In second object based on the DynamicKey value need to create the key and values .

 this.RootKeyValue = "AccountDetails";
this.keyResponse = 
    {ICICI: 2,DynamicKey: "ICICI"},
    {SBI: 1.25,DynamicKey: "SBI"}
    {HDFC: 1.75,DynamicKey: "HDFC"}
how to construct the object like below using above key and response

    Expected resut : 
   AccountDetails : 
    { ICICI :2 , SBI: 1.25,HDFC: 1.75 } 
    I am new to react please suggest how to construct object using the dynamic key values

94 thoughts on “Constructing object array using dynamic keys in react/Javscript”

Leave a Comment