jQuery inArray is always returning -1

后端 未结 6 918
遥遥无期
遥遥无期 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:07

    This confused me too at first, I had an identical problem. It seems jQuery.inArray() requires a string. So you could just do:

    var lastProductID = "6758";

    In my case I was trying to do:

    var foo = date.getTime()/1000;

    Which always resulted in -1 being returned from $.inArray()

    But you can just cast it to a string:

    var foo = String(date.getTime()/1000);

    Hope that helps somebody :)

提交回复
热议问题