We have two arrays to work with here. The first array consists of objects:
let objectArray = [{
FullName: "Person1",
PersonId: "id1"
},
{
FullName: "Person2",
PersonId: "id2"
},
{
FullName: "Person3",
PersonId: "id3"
},
{
FullName: "Person4",
PersonId: "id4"
}
];
The second array contains strings which are some ids:
let idsArray= ["id1", "id2", "id3"];
The task at hand is to remove the objects from the first array that have ids present in the second array.
The expected result after deletion is as follows:
firstArray = [{
FullName: "Person4",
PersonId: "id4"
}];
While exploring documentation on Linqjs
, I came across the Except()
method, which aids in eliminating elements from one array based on another.
To utilize this method effectively, a new array needs to be created from objectArray
only containing elements whose ids match those in idsArray
.
For example:
let filteredArray = Enumerable.From(objectArray).Except(theNewArray).ToArray();
The creation of this new array can be achieved by using the Where()
method provided by Linqjs
.
The major challenge I face now is figuring out how to generate this new array while considering we have an array of ids for filtering purposes.