Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IN Operator in Javascript functions like the one in SQL

I have tried the following but it's throwing an exception:

                if (!$get('sslot_hf0').value in ('X', 'Y', 'Z', '0')) {
                $get('sslot_hf0').value = 'X';
            }

I am looking for a function similar to the IN operator in SQL

like image 544
Alaa Avatar asked Jan 01 '13 05:01

Alaa


1 Answers

You can use indexOf

['X', 'Y', 'Z', '0'].indexOf('Z')
> 2
['X', 'Y', 'Z', '0'].indexOf('T')
> -1

if (['X', 'Y', 'Z', '0'].indexOf($get('sslot_hf0').value) !== -1) {
  //...
}
like image 116
sachleen Avatar answered Oct 08 '22 09:10

sachleen