![](/img/trans.png)
[英]Do you have to check for null & length or is there a shorter way to verify a non-empty string?
[英]Is there a much more cleaner and shorter way to check if string is empty?
我正在我的快递服务器上工作,我正在尝试验证一些查询参数。 例如,我可以有查询参数date
,它可能是 null 或空字符串。 现在当前的验证是这样的
if(req.query.date && req.query.date !== '')
有没有像 function 或像_lodash
这样我可以使用的库来保持更整洁?
您的解决方案已经很简洁了,您可以将其简化为
if(req.query.date)
尽量不要过度使用lodash
或其他包,你可以自己编写这些东西,但是所有这些多余的包只会淹没你的包,让它变得更重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.