I have a requirement wherein I get nested object keys in an array. I have an array of keys like
let keys = ["vehicleInformation", "VehicleBlock|1", "DriverAssociation|1", "DriverInvolvedAssociation"]
There is already a JSON data that is stored in a variable and I have to update a data object.
data['vehicleInformation']['VehicleBlock'][1]['DriverAssociation'][1]['DriverInvolvedAssociation'] = value;
Is there a way to achieve this in javascript? Initial value of data:
data = {};
Expected result:
data = {
vehicleInformation: {
VehicleBlock: [
{},
{
DriverAssociation: [
{},
{DriverInvolvedAssociation: value},
],
},
],
},
};