I have one array which collects objects. I want to implement insert operataion function which gets some path array "idsListPath" and the new object which we want to insert "itemToInsert".
EXAMPLE:
function InsertIntoDataSet(idsListPath, itemToInsert)
//idsListPath: the path where i want to add "itemToInsert" object
{
//How do i push the itemToInsert in correct path?
}
SAMPLE DATA:
var idsListPath = ["1", "3", "44"];
var itemToInsert = { id: "111", node: [] };
var dataSet = [{
id: "1", node: [
{
id: "98",
node: []
},
{
id: "3",
node: [{
id: "44",
node: [] //TARGET LOCATION TO PUSH THE NEW ITEM
}]
}]
},
{
id: "3",
node: []
},
{
id: "44",
node: []
}];
As in sample our path is "1", "3", "44"...
So new object item should insert into dataSet of the object having id "1" > Its child node having id "3" > its child node having id "44" > under node [] i want to push the new object item.
How can i achieve this? Even if "idsListPath" array have single value that function should work.