0

If I have two separate objects in Javascript:

test_object_1 = {name: "tom", age: 22, occupation: "bus driver", favorite_color: "blue"};
test_object_2 = {name: "howard", age: 22, favorite_color: "blue", occupation: "dog walker"};

How would I go about comparing seeing if there was two matching key, value pairs. I would prefer if it was multiple functions, I am trying to do it in the most understandable way possible. (I would prefer not to use .hasOwnProperty because I do not yet understand it, if used please explain its use explicitly)

It should return true for both age and favorite_color.

Paul Duca
  • 31
  • 6
  • 2
    Loop over the keys, reference both objects, see if that key matches. – epascarello Aug 29 '16 at 13:41
  • 1
    Instead of deciding not to use a feature because you do not understand it, why don't you learn it? –  Aug 29 '16 at 14:12
  • 1
    I am trying to, but can't figure it out. Which is why the other answer on Stack overflow which my question is marked to duplicate uses doesnt make sense to me. – Paul Duca Aug 29 '16 at 14:15
  • I edited my question to reflect this! @torazaburo – Paul Duca Aug 29 '16 at 14:16
  • Do you want to match where both objects have the same key with the same value as well, or just that the key exists on both? – BadHorsie Aug 31 '16 at 13:22

0 Answers0