开发者

Javascript wildcard inside of condition?

开发者 https://www.devze.com 2023-03-24 01:24 出处:网络
I have a basic javascript conditional statement for filtering through some items, it looks like this:

I have a basic javascript conditional statement for filtering through some items, it looks like this:

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.

Is ther开发者_JAVA百科e a way this can be done? when I try: if(item == "*") it returns no results.

Thank you


Try

if(!var_condition || item == var_condition) {//do this }


you can try:

if(item === (var_condition || item)) { /*do this*/}
0

精彩评论

暂无评论...
验证码 换一张
取 消