I have two Arrays of Objects. While localDataArray is is already stored inside my app,remoteUpdateDataArray comes from the backend.
var localDataArray = [
{ "date": "10/01/19", "category": "surf", "hash": "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
{ "date": "10/01/19", "category": "skate", "hash": "a0f1490a20d0211c997b44bc357e1972deab8ae3"},
{ "date": "10/01/19", "category": "skate", "hash": "54fd1711209fb1c0781092374132c66e79e2241b"}
];
var remoteUpdateDataArray = [
{ "date": "12/01/19", "category": "surf", "hash": "4a0a19218e082a343a1b17e5333409af9d98f0f5"},
{ "date": "11/01/19", "category": "surf", "hash": "54fd1711209fb1c0781092374132c66e79e2241b"},
{ "date": "10/01/19", "category": "surf", "hash": "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
{ "date": "10/01/19", "category": "skate", "hash": "a0f1490a20d0211c997b44bc357e1972deab8ae3"},
{ "date": "10/01/19", "category": "skate", "hash": "54fd1711209fb1c0781092374132c66e79e2241b"}
];
I want to remove all duplicated objects from remoteUpdateDataArray. The unique identifier of each object is the hash.
So far, I have the following code:
let hashValue = "54fd1711209fb1c0781092374132c66e79e2241b"
var filteredResult = remoteUpdateDataArray.filter(x => x.hash !== hashValue);
Result:
var filteredResult = [
{ "date": "12/01/19", "category": "surf", "hash": "4a0a19218e082a343a1b17e5333409af9d98f0f5"},
{ "date": "11/01/19", "category": "surf", "hash": "54fd1711209fb1c0781092374132c66e79e2241b"},
{ "date": "10/01/19", "category": "surf", "hash": "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
{ "date": "10/01/19", "category": "skate", "hash": "a0f1490a20d0211c997b44bc357e1972deab8ae3"}
];
How do I manage to also get rid of the other (in this case two duplicate objects) inside the array? Keep in mind that these arrays may get pretty big.
localDataArrayif it actually doesn't matter for your problem?