If in Input2 Products and Roles object required key is false, then Products and Roles should be removed from input1.
If any one required is true, Products and Roles should not be removed.
In input2 if there is an object other than Product or Roles, then only attributes in input1 should be shown otherwise it should be removed.
input1 = [
{ name: "Basic Details", description: "abc" },
{ name: "Products and Roles", value: "def" },
{ name: "Attributes", value: "ghi" }
];
input2 = [
{key: "Product", type: "", value: "", required: false, mandatory: false },
{ key: "Roles", type: "", value: "", required: false, mandatory: false },
{ key: "sad", type: "text", value: "", required: false, mandatory: false},
];
expected output
input1 = [
{ name: "Basic Details", description: "abc" },
{ name: "Attributes", value: "ghi" }
];
input2.filter(elm => {
if(elm.key === 'Product' && !elm.required) {
input1.filter(el => el.name !== 'Products & Roles');
}
});
console.log(input1);