Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

find specific number in array for if statement

I know there are alot of questions like this on here but they keep pointing me to using includes and that is not working for me for some reason.

Goal – use an if statement to find out if a number exists in an array. (Don’t care if its jQuery or plan JS)

I tried using includes but that failed:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

testdata = [1,256]
testdata.includes(1) #or testdata.includes(256)
\\false

enter image description here

I also tried using indexof but that failed too:

testdata = [1,256]
testdata.indexOf('256') >= 0
\\false

enter image description here

>Solution :

Indeed, it looks like your array [1,256] is the first element of testdata array. In fact, you can see that testdata length is 1.

You should check if testdata[0].includes(1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading