Here's my goal: compare two objects and figure out if there is 1 or more items in common. If there are 1 or more in common, return true otherwise (no items in common), return false.
Current issues: I'm trying to use the .some() method with 1 object from an API and 1 object that's local, but a bit confused why it's not working...any ideas? It should return true since John is in both objects, but it returns false
Code example: in this example, it should return true because John is a name that is both object 1 (result1) and object 2 (result 2). However, it returns false.
Is anyone able to help me understand what I'm doing wrong here?
var result1 = [
{id:1, name:'Sandra', type:'user', username:'sandra'},
{id:2, name:'John', type:'admin', username:'johnny2'},
{id:3, name:'Peter', type:'user', username:'pete'},
{id:4, name:'Bobby', type:'user', username:'be_bob'}
];
var result2 = [
{id:2, name:'John', email:'johnny@example.com'},
{id:4, name:'Bobby', email:'bobby@example.com'}
];
const hasSimilarElement = result1.some((item) => item.name === result2.name);
console.log(hasSimilarElement);