I have an array with objects like so:
tree = [
{
id: 1,
name: "parent1",
children: [
{
id: 2,
name: "child1",
children: [
{ id: 4, name: "subChild1",dateType:"hijri" },
{ id: 5, name: "subChild2",dateType:"hijri" }
]
},
{ id: 3, name: "child2" }
]
}
];
and another array like:
result= [{id:4,dateType:"Geo"},{id:5,dateType:"another"}]
i want loop through the second array and for each node in the first array meet the condition id=id ,i need to change the dateType value for it, like this:
this.result.forEach(res => {
this.flattenItems(this.tree).find(
item => item.id == res.id
).itemType =res.dateType;
});
noting that the tree is from 3 levels and the operation only on the last level
Is there any way to implement the loop using lodash?