Wherefore art thou. Array problem

Tell us what’s happening:
Hi, here I have chosen to loop through the collection, and find the items that have the same properties as source does, before comparing the values of the properties, and push it into the arr if they are the same. I’m not sure what went wrong here. the returned arr contains only the property pairs that matched, instead of the collection item that contains the matched pairs.
Can someone help me? thanks

Your code so far


function whatIsInAName(collection, source) {
  // What's in a name?
  let arr = [];
  // Only change code below this line
  for(let i in source){
    for(let j = 0; j < collection.length; j++){
     if(collection[j].hasOwnProperty(i)){
       if(collection[j][i]===source[i]){
          arr.push(collection[j])
       }
}
  }
}
console.log(arr)
   // Only change code above this line
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou

Hi, thanks for the detailed reply. I have used another method to solve this problem. But this time something else has gone wrong. Here I try to turn both source and collection into arrays, so that I can check if any arrays in collection are identical to those of the source. I will turn them back into objects again when returning. But the filter method here is not working. The console has given a hint, but I do not understand what it means. Much appreciated if you had any advice!