I am currently working on a task that involves checking if the values of one array of objects exist in another array of objects. The goal is to disable a table row if the values match. Below are the two arrays of objects I am working with.
const array1 = [
{
id: "8a8080877134b405017134c1adb3004f",
name: "AWS API1"
},
{
id: "8a8080b6720900d301720935a7120000",
name: "AWS API3"
},
{
id: "8a80808271773317017177848a5106d1",
name: "AZURE API1"
}
];
const array2 = [
{
apiId: "8a8080877134b405017134c1adb4444f",
apiName: "AWS API2"
},
{
apiId: "ass34dgdfgfdgfdg35435ERF",
apiName: "AZURE API1"
},
{
apiId: "dfdfdaggfdgdfg4324564",
apiName: "AWS API1"
}
];
In order to achieve my objective, I need to compare the values of 'array1.name' with 'array2.apiName', and disable the table row if they match. How can this be accomplished?
Please refer to the code snippet below for implementation.
const result = array1.filter((element) => !array2.find(({ apiName }) => element.name === apiName));
console.log(result);