0

I am building an integration and I have two objects. The makeup of the objects is as follows:

var objectA = {};
objectA['alpha'] = 'charlie';

var objectB = {};
objectB['bravo'] = 'charlie;

What I want to know is given the two objects above is it possible to compare the two value to see if they are different?

Please note that the objects make up are completely different for both objects but I just need to compare the values.

GhostDZ9
  • 145
  • 1
  • 6
  • 18
  • What exactly do you mean compare? Do you mean something like magicFunction(object,property,object2,property2)? – TheGenie OfTruth Nov 29 '16 at 03:00
  • 1
    `if(objectA.alpha === objectB.bravo)` or `if(objectA['alpha'] === objectB['bravo'])` – StackSlave Nov 29 '16 at 03:00
  • Are you trying to find a way, given two objects, to see if any of their properties match? Will these objects always have one property? – Nick Zuber Nov 29 '16 at 03:00
  • 1
    `objectA.alpha === objectB.bravo)` – Luminous_Dev Nov 29 '16 at 03:02
  • I am looking for a way to see if their properties match. There will not be any nested properties only one property. – GhostDZ9 Nov 29 '16 at 03:03
  • I don't want to compare the entire object. Just the values in the object. – GhostDZ9 Nov 29 '16 at 03:04
  • @Bergi Unfortunately, that still isn't a great dup, since it's about comparing objects, whereas this gentleman is comparing, or rather trying to compare, primitives. The problem is that this question is so elementary and rudimentary that it probably has not been asked before. However, in the interest of keeping the question closed, I guess we should just leave it as is. –  Nov 29 '16 at 13:38

1 Answers1

0

You can do this:

objectA.alpha === objectB.bravo

OR

objectA['alpha'] === objectB['bravo']

Assuming alpha and bravo are not Objects again.

yadhu
  • 15,423
  • 7
  • 32
  • 49
  • This will return true if they are equal and false if they are not equal correct? – GhostDZ9 Nov 29 '16 at 03:07
  • Yes of course. You can try that in your browser console. `var objectA = { alpha: 'charlie' }; var objectB = { bravo: 'charlie' }; console.log(objectA.alpha === objectB.bravo);` – yadhu Nov 29 '16 at 03:10
  • What's next? Answering a question about how to multiply two values in JavaScript by using the star? –  Nov 29 '16 at 13:35