Skip to content
Advertisement

How to cast string boolean from MySQL to real boolean in Javascript?

I built a php backend for my ReactJS frontend.

My mysql users table has a checkedIn column that is stored as tinyint. I am fetching it like:

JavaScript

And in my frontend:

JavaScript

My log gives me:

JavaScript

How can I modify my backend or my frontend, to have a real boolean value for checkedIn in the frontend?

I expect:

JavaScript

As a side effect: How can I cast the id to Number and the timestamp to Date?

Advertisement

Answer

Create a function convert do these conversion:

JavaScript

Note: user has JSON format. So convert it to real object using function JSON.parse()

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement