1
I have the following object array:
let items = [
{
carro: {
title: "Gol",
description: "Gol quadrado",
active: true,
},
isVisible: true,
},
{
carro: {
title: "Gol Filho",
description: "Gol quadrado",
active: true,
},
isVisible: true,
parent: 'Gol'
}]
There is a simple way to loop inside this array and check if any element has the string Parent equal to title of some element and add that element within the object that satisfies that condition?
Example:
let items = [
{
carro: {
title: "Gol",
description: "Gol quadrado",
active: true,
},
isVisible: true,
children: [
{
carro: {
title: "Gol Filho",
description: "Gol quadrado",
active: true,
},
isVisible: true,
parent: 'Gol'
}
]
}]
The logic is this, take everyone who doesn’t have
parent
and take everyone who hasparent
and make the junction of information, there is nothing magical needs to be done so some code to separate and then merge, you made some code?– novic
You changed the original question and there is no recursion of children with children’s children, nor does the question make this kind of junction so the answer does what you ask and I will reverse the edition, if you want to please open another question and be as clear as possible.
– novic