I have this "data" object that already map and I need to mapping the cmsmenuschild and put it at "children:[]" because it has data array of object too and I want to change the cmsmenuschild payload id and name to be key and title , like I just done to id and name before. I really new at React so I,m still figuring out how to do the map inside a map like this.any help would be appreciate
constructor(props) {
super(props);
this.state = {
listMenu: []
};
}
data = [
{
"id": 1,
"name": "Manage User",
"cmsmenuschild": [
{"id": 14,"name": "Create User"},
{"id": 15,"name": "Update User"},
]
},
{
"id": 2,
"name": "Manage BTP",
"cmsmenuschild": [
{"id": 18,"name": "Create BTP"},
{"id": 19,"name": "Update BTP"},
]
},
]
const privilegesData = this.data.map((privilege) => {
return {
key: privilege.id,
title: privilege.name,
children:[{
key: privilege2.id,
title: privilege2.name,
}],
};
});
this.setState({
listMenu: privilegesData,
});
expected to display new this.state.listMenu woudl be like this
this.state.listMenu : [
{
"key": 1,
"title": "Manage User",
"children": [
{"key": 14,"title": "Create User"},
{"key": 15,"title": "Update User"},
]
},
{
"key": 2,
"key": "Manage BTP",
"children": [
{"key": 18,"title": "Create BTP"},
{"key": 19,"title": "Update BTP"},
]
},
]
cmsmenuschild. Just useprivilege.cmsmenuschildto have its array data in thechildrenkey.