-1

I have checked this question, adn also this but still my problem persists. I need to store in Mysql in VARCHAR field different data, like true, false, numbers and other strings. When I get 'true' or 'false' strings from my DB, in my JS code I need to check that it is boolean type, hence return true both for true and false values, ore something like typeof Boolean === true, in other case return false. I tried many variants from the above mentioned questions, but all solutions returned true if the value was true and false if the values was false which is wrong for me. Any ideas how to do that would be welcome. Thank you.

Masha
  • 827
  • 1
  • 10
  • 30

2 Answers2

1

To determine if the value is one of "true" or "false":

if (value === "true" || value === "false")
user94559
  • 59,196
  • 6
  • 103
  • 103
0

You could check the value first, if it should be a boolean and then convert it or return the original value.

value = value === 'true' || value === 'false' ? value === 'true' : value
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392