I am looking for a solution which would take a path and an object as input and create/add the object in the specified path of the nested parent object.
var obj = {};
function addHandle(object, path, handle){
//logic
}
addHandle(obj, "order/customer/name", "abc");
addHandle(obj, "order/customer/address[]/line1", "address 1");
addHandle(obj, "order/customer/address[]/line1", "address 2");
The expected output should be
"order":{
"customer":{
id":"abc",
"address":[
{
"line1":"address 1"
},{
"line2":"address 2"
}
]
}
}
}
Can you please help me with the function logic ?