var x = new Array(10);
$.inArray(10,x);
#Returns -1
I’ve come across this weird issue, checking a value in an array with $.inArray, really simple.
But, if the array only has one value in it, inArray returns -1.
If I add another value to the array, it works as expected.
This only happens with integers and not with strings.
What’s going on?!
If you want to create an array with the one number(
10) inside you should use bracket literal:Or with push:
Obviously the first one is more readable and faster to write.
Fixed fiddle