3

How can I check if two JavaScript values are the same?

If they are objects, I would like to compare them key-by-key recursively.

I'm looking for an existing function, not a way to write my own like described in this question: Object comparison in JavaScript.

Community
  • 1
  • 1
Martin Konicek
  • 39,126
  • 20
  • 90
  • 98

3 Answers3

5

There's a function called deepDiffer which does this.

Martin Konicek
  • 39,126
  • 20
  • 90
  • 98
2

Took a bit of Googling to find how to import deepDiffer.

import deepDiffer from 'react-native/lib/deepDiffer'

...

deepDiffer(obj1, obj2) // true or false
dB.
  • 4,700
  • 2
  • 46
  • 51
2

In react native >= 0.62.2 use,

import deepDiffer from `react-native/libraries/utilities/differ/deepDiffer`

deepDiffer(obj1, obj2) // true or false
Namit Gupta
  • 796
  • 9
  • 20