Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  49] [ 4]  / answers: 1 / hits: 53670  / 14 Years ago, wed, march 9, 2011, 12:00:00

In SQL Server, I could say:



WHERE X IN(1,2)


How would you rewrite the following in JavaScript:



if (X==1 || X==2) {}

More From » javascript

 Answers
8

Use indexOf to see if x is in an array.



if([1,2].indexOf(x) !== -1)

[#93352] Tuesday, March 8, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leiaf

Total Points: 10
Total Questions: 101
Total Answers: 84

Location: Guam
Member since Tue, Nov 29, 2022
2 Years ago
;