I need to add key and its value in a existing json array using Javascript. I am explaining my array below.
var finalOut=[
            {
                "location": "Jaipur",
                "nos_of_fos": 4,
                "login_id": [
                    "9619300332",
                    "9619300347"
                ],
                "total_remarks": 0,
                "total_disposition_code": {"PTP": 3,
                    "CB": 1,"TPT":4}
            },
            {
                "location": "BHILWARA,",
                "nos_of_fos": 1,
                "login_id": [
                    "9619300346"
                ],
                "total_remarks": 4,
                "total_disposition_code": {
                    "PTP": 3,
                    "CB": 1
                }
            },
            {
                "location": "AJMER",
                "nos_of_fos": 2,
                "login_id": [
                    "9619300357"
                ],
                "total_remarks": 0,
                "total_disposition_code": {}
            }
        ]
Here I need if total_disposition_code has any value then its all key and value will add in  root object and the expected output result is given below.
 var result=[
                {
                    "location": "Jaipur",
                    "nos_of_fos": 4,
                    "login_id": [
                        "9619300332",
                        "9619300347"
                    ],
                    "total_remarks": 0,
                    "PTP":3,
                    "CB":1,
                    "TPT":4
                },
                {
                    "location": "BHILWARA,",
                    "nos_of_fos": 1,
                    "login_id": [
                        "9619300346"
                    ],
                    "total_remarks": 4,
                    "PTP":3,
                    "CB":1,
                },
                {
                    "location": "AJMER",
                    "nos_of_fos": 2,
                    "login_id": [
                        "9619300357"
                    ],
                    "total_remarks": 0,
                }
            ]
I need the above format using javascript. I have also tried the below code.
for(var key in finalOut){
     finalOut[key]['total_disposition_code'][key]=
    //console.log(finalOut[key]);
}
 
    