0

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

Jonny
  • 843
  • 12
  • 18
  • 2
    Does this answer your question? [Comparing Arrays of Objects in JavaScript](https://stackoverflow.com/questions/27030/comparing-arrays-of-objects-in-javascript) It's one of the most commonly asked JavaScript questions. – Yogi May 31 '22 at 21:20

0 Answers0