Home > Back-end >  How to check if data is key-value format in react native?
How to check if data is key-value format in react native?

Time:06-18

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.

CodePudding user response:

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.

CodePudding user response:

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
}
  • Related