I have array of object and need to modify and return new array of object
For the below array of object, i need to return new array of object with label, value and children props using javascript.
should change every property value to label, value and if property value is array then embed in children prop as shown in expected output
var arrobj = [
{
title: "Test A",
group: ['Travel', 'Health'],
details: {
'Travel': ['domestic', 'international'],
'Health': ['hospital']
}
},
{
title: "Test B",
group: ['Finance'],
details: {
'Finance': ['family']
}
}
]
Expected Output:
[
{
value: "Test A",
label: "Test A",
children: [
{
value: 'Travel', label: 'Travel',
children: [
{ value: 'domestic', label: 'domestic'},
{ value: 'international', label: 'international'},
]
},
{
value: 'Health', label: 'Health',
children: [
{ value: 'hospital', label: 'hospital'},
]
}
]
},
{
value: "Test B",
label: "Test B",
children: [
{
value: 'Finance', label: 'Finance',
children: [
{ value: 'family', label: 'family'},
]
}
]
}
]
Tried
arrrobj.map(e=> {
label: e.title,
value: e.title,
children: [
{
label: e.group;
value: e.group;
children: e.details.Travel
}
]
})
3
Answers
Here’s a solution:
like this ?
or is there any more message ?