Wednesday 17 January 2018

Test for value in Javascript Array






In SQL Server, I could say:



WHERE X
IN(1,2)


How would you
rewrite the following in
JavaScript:



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

itemprop="text">
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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...