Javascript wildcard inside of condition?
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*/}
精彩评论