I have two arrays such as,
Array 1:
deletedValuesfromArray =
[
{ "property_name": "Property three", "property_type": 4, "property_required": true, "property_origin": 2 },
{ "property_name": "rstywrtre", "property_type": 3, "property_required": true, "property_origin": 1 }
]
Array 2:
normalArray =
[
{ "property_name": "Property one", "property_type": 4, "property_required": true, "property_origin": 1 },
{ "property_name": "Property two", "property_type": 5, "property_required": true, "property_origin": 1 },
{ "property_name": "Property three", "property_type": 4, "property_required": true, "property_origin": 2 },
{ "property_name": "rstywrtre", "property_type": 3, "property_required": true, "property_origin": 1 }
]
I would like to compare both arrays and filter the array to get the new one after removing the deletedValuesfromArray
(Array 1).
For which i have tried the following,
let newArray = this.normalArray.filter(function (val) {
return this.deletedValuesfromArray.indexOf(val) == -1;
});
console.log(newArray);
But it doesn't works..
Expected Output is,
New Array
[
{ "property_name": "Property one", "property_type": 4, "property_required": true, "property_origin": 1 },
{ "property_name": "Property two", "property_type": 5, "property_required": true, "property_origin": 1 }
]
Stackblitz that i have tried
The values also will not be unique always it may have a complete duplicate of any object.
How to compare and remove the deleted values from the normal array and get the newarray?