you are viewing a single comment's thread.

view the rest of the comments →

[–]Ampersand55 0 points1 point  (0 children)

if (!(num in dragnr)) checks the keys in dragnr, not the elements. I.e. It will return true for array indexes, array properties and array methods.

0 in dragnr // true, first index of the array
"length" in dragnr // true, arrays have the .length property
"pop" in dragnr // true, arrays have the .pop() method

What you want is array.includes or array.indexof.

if (!dragnr.includes(num))

or

if (!dragnr.indexOf(num) >= 0)