At this point, I check if elements in an node.js object exist and get the value by doing:
if(req.body.name) item.name = req.body.name;
However, if I want to do the same for a boolean element, it is not working. If the passed boolean is true, no problem, but if the passed boolean is false, the if statement fails, however, I need the value of it:
if(req.body.active) item.active = req.body.active; // works only if true
Is there a better way to check if an element in an object exists and to validate the boolean value of it?
A few, you probably want in:
if("active" in req.body)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With