jQuery inArray is always returning -1

后端 未结 6 919
遥遥无期
遥遥无期 2020-12-09 09:40

I cannot figure out why I keep getting -1 for lastProductIndex when clearly the lastProductID is in the array!

var lastProductID = 6758;
var allProductIDs =          


        
6条回答
  •  醉梦人生
    2020-12-09 10:03

    Try this instead:

    $.grep(allProductIDs, function(n) { return n == lastProductID; });
    

    Caveat: grep returns an array.

    It looks like jQuery does an === instead of == with inArray.

提交回复
热议问题