I have seen some answers on how to compare two arrays in javascript, but my problem is a little bit different. My arrays contain objects with values that I want to compare.
I have two arrays (of different lengths), example here for brevity:
let arr1 = [
{
name: "something"
},
{
name: "somethingElse"
}
]
let arr2 = [
{
nickname: "somewhere"
},
{
nickname: "something"
},
{
nickname: "who"
}
]
I want to be able to find a way to check if the same value exists in both arrays.
I imagine it's some sort for sort / includes / for loop, but I just can't get the syntax to say:
Check arr1, see if any of the name values match the nickname values in arr2. Return the items in the arr2 array that do (or don't) match