[英]Javascript wildcard inside of condition?
I have a basic javascript conditional statement for filtering through some items, it looks like this: 我有一个用于过滤某些项目的基本javascript条件语句,它看起来像这样:
if(item == var_condition) { //do this }
Now what I would like for the var_condition
is, if I have a variable condition available than var_condition = my condition
, but if I don't have a condition available than var_condition = *
, meaning item could equal anything. 现在我想要的var_condition
是,如果我有一个可变条件而不是var_condition = my condition
,但是如果我没有一个可变条件是var_condition = *
,则意味着item可以等于任何东西。
Is there a way this can be done? 有办法吗? when I try: if(item == "*")
it returns no results. 当我尝试: if(item == "*")
,不返回任何结果。
Thank you 谢谢
尝试
if(!var_condition || item == var_condition) {//do this }
你可以试试:
if(item === (var_condition || item)) { /*do this*/}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.