I want to be able to return duplicates except first occurance in an array of objects based of the place and keyword. Both should match and return the documents in an new array. Here is my trial run:
var things = [
{place: 'hello', keyword: 'hey', id: 0},
{place: 'hi', id: 1},
{place: 'hello', keyword: 'hey', id: 2},
{place: 'hello', keyword: 'man', id: 3}
]
var duplicates = [];
things.forEach((item, index) => {
if(things.indexOf(item.place) != index && things.indexOf(item.keyword) != index) {
duplicates.push(item);
}
});
Expected output:
[{place: 'hello', keyword: 'hey', id: 2}]
Any help would be great (without any frameworks, just ES6 or older). Thanks
EDIT: It should match multiple specified values such as keyword and place.
{place: 'hello', keyword: 'man', id: 3}to be in the output as well