R
Reactiflux

help-js

✅ – Script – 21-22 Nov 7

SScript11/7/2022
How do I check if boolean object key contains value? Category is a string, so I just check if it contains any value and then I am able to update it
gig.category = req.body.category ? req.body.category : gig.category;
gig.category = req.body.category ? req.body.category : gig.category;
but approvedForMenu is a boolean. So my ternary operator is checking for true or false instead. I can change the value to true but I cant change it back to false. How do I write the code so I can be able to change it back to false?
gig.approvedForMenu = req.body.approvedForMenu ? req.body.approvedForMenu : gig.approvedForMenu;
gig.approvedForMenu = req.body.approvedForMenu ? req.body.approvedForMenu : gig.approvedForMenu;
SScriptyChris11/7/2022
You can use ??, which checks for null/undefined instead of truthiness/falsiness @Script https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
SScript11/7/2022
truly the learning dont stop. haha thanks Chris
UUUnknown User11/8/2022
3 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!