0

I'd like to know the solution to check the data format is key-value or not in react native. If someone knows it, let me know please. Thank you.

ATEC HUO
  • 3
  • 2
  • Does this answer your question? [Check if a value is an object in JavaScript](https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript) – Thanhal P A Jun 17 '22 at 05:04

2 Answers2

0

a = {'a':1,'b':2} result = a instanceof Object && !(a instanceof Array)

result will be true if variable a contains key-value pairs.

  • 'a instanceof Object' returns true when a is an array also. That is why the second condition is there.
Arun P S
  • 11
  • 2
0

If you want to know a variable is instance of Object or not, you are be able to easily do this:

if (typeof myVariable === 'object') {
  //do something
} else {
  //do something
}
MHP
  • 577
  • 5
  • 9