I have an array with objects:
var test = [
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "Some one else home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home1",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
}
];
I would like to mark the objects that they are duplicates, like this (notice the extra property, isDuplicate):
var test = [
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "Some one else home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity",
isDuplicate: true
},
{
type: "home1",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity"
},
{
type: "home",
name: "My home",
country: "DE",
postalZone: "1234",
cityName: "GermanCity",
isDuplicate: true
}
];
If one of the above values change (type, name, country, postalZone or cityName), the object is unique.
I have tried the following for testing purpose. Getting only the unique objects for "type", does not work for me e.g.
_.uniq(test, "type");
Still getting all the array objects. Ofcourse I want to check on more object keys, not only on type, but on all object keys (type, name, country, postalZone or cityName).
The native array function "some", stops if it finds the first duplicate, for me it should not stop...
How can I achieve this?
I have Lodash v4.13.1.