I am having an issue where jQuery.InArray() is returning -1 when I run a function, but I know that the values that I'm testing for are definitely in the array.
I know that they are in the array because if I console.log the values of the array right before I run jQuery.inArray() the values exist and display. Here is an example of what I'm working with:
/* -- In page.php -- */
images = [8, 13, 21, 32, 40, 56];
/* -- In script.js -- */
console.log('images->', images);
//output images-> [8, 13, 21, 32, 40, 56]
var testingValue = 13;
console.log('inArray->', jQuery.inArray(testingValue, images)); //Should return 1
//output inArray-> -1
console.log('inArray->', jQuery.inArray(13, images)); //Should return 1
//output inArray-> -1
console.log('inArray->', jQuery.inArray("13", images)); //Should return -1
//output inArray-> -1
console.log('inArray->', jQuery.inArray('13', images)); //Should return -1
//output inArray-> -1
All of these return -1 even though the top two should return 1. The weird thing is that if I manually test for jQuery.inArray(testingValue, images) in the console, I do get the value 1.
One thing to note: The variable images is created in the php page that the js file is included in. This shouldn't be an issue.
Additional note: Yes, jQuery is included well before this part of the script runs. Many other jQuery functions are running successfully before this one.
What I am wondering is if there are any gotchas to this function. I have used it successfully in the past and can't see anything with my code which would prevent this from returning a proper value.
imagesgot overwritten or something. You cans set breakpoints and have a watch monitor that variable.