jQuery inArray is always returning -1

jquery

Solution

I had the same problem yesterday,,

var data=[2,4,6,8];
alert( $.inArray(4,data) ) // output 1 as expected
alert( $.inArray("4",data) ) // output -1 as expected 

Generally this occurs when you get the value to check from a input element or something that returns a string. You need to do `parseInt(string,radix)` to convert it to a number...

Problem

I cannot figure out why I keep getting -1 for lastProductIndex when clearly the lastProductID is in the array! ``` var lastProductID = 6758; var allProductIDs = [5410, 8362, 6638, 6758, 7795, 5775, 1004, 1008, 1013] var lastProductIndex = $.inArray(lastProductID, allProductIDs); ```

Original source