So there's lots answers to this if the objects are equal. But in my case I want return only if certain fields are equal and i haven't been able to find any answers to this.
Let's say i have this array of objects:
let obj = [
{ name: 'bob', adress: 'somewhere1', country: 'sweden', nr: '1235'},
{ name: 'bob', adress: 'somewhere1', country: 'norway', nr: '7656'},
{ name: 'john', adress: 'somewhere2', country: 'denmark', nr: '54534'},
{ name: 'john', adress: 'somewhere2', country: 'US', nr: '3333'},
{ name: 'steven', adress: 'somewhere3', country: 'UK', nr: '5467'}
]
I want to filter this by name and address if they are equal, add them to a new array:
let newObj = [
[{
name: 'bob',
adress: 'somewhere1',
country: 'sweden',
nr: '1235'
},
{
name: 'bob',
adress: 'somewhere1',
country: 'norway',
nr: '7656'
}
],
[{
name: 'john',
adress: 'somewhere2',
country: 'denmark',
nr: '54534'
},
{
name: 'john',
adress: 'somewhere2',
country: 'US',
nr: '3333'
}
],
[{
name: 'steven',
adress: 'somewhere3',
country: 'UK',
nr: '5467'
}]
]