jQuery inArray is always returning -1

后端 未结 6 992
遥遥无期
遥遥无期 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 09:55

    Are you using any other JavaScript libraries in your page?

    There could be a conflict for the $ shorthand if you are. This can be solved in a number of ways, one of which would be wrapping the code in a self-executing anonymous function

    (function($) {
        var lastProductIndex = $.inArray(lastProductID, allProductIDs);
    })(jQuery);
    

提交回复
热议问题