so you can get keys
of the permission
array, this would give you an array of keys.since you are getting the keys
of an item in an array of objects so the key
would always be the first item then you can check each data item with that key
const PermissionObj = {
permission: [
{
books: [
{
label: "Can View",
value: "can_view"
}
]
},
{
Journals: [
{
label: "Can View",
value: "can_view"
},
{
label: "Can Create",
value: "can_create"
}
]
},
{
deal: [
{
label: "Can update",
value: "can_update"
},
{
label: "Can delete",
value: "can_delete"
}
]
}
]
};
const data = [
{
label: "books",
value: "can_view"
},
{
label: "deal",
content: [
{
value: "can_update"
},
{
value: "can_delete"
}
]
},
{
label: "Articles"
},
{
label: "Journals",
content: [
{
value: "can_create"
},
{
value: "can_view"
}
]
}
];
let permission = PermissionObj.permission;
let NewData = [];
permission.filter(item => {
let ObjectKeys = Object.keys(item);
let ObjKey = ObjectKeys[0];
let DATA = data.find(
dataItem => dataItem.label.toString() === ObjKey.toString()
);
NewData.push(DATA);
});
console.log(NewData);