In SQL Server, I could say:
WHERE X
IN(1,2)
How would you
rewrite the following in
JavaScript:
if (X==1 || X==2)
{}
class="normal">Answer
Use href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"
rel="noreferrer">indexOf
to see if
x
is in an
array.
if([1,2].indexOf(x) !==
-1)
No comments:
Post a Comment