0
for (index=1; index<=15; index++) {
    if (undefined != sku[index]) {

        found = jQuery.inArray(sku[index], mr_sku); 
        if( found == -1){ //not in array
            alert( sku[index] + " NOT FOUND - delete index " + index );
        } else { // in array
                  alert("FOUND");
        }

  }

}

两个数组 - sku 和 mr_sku = 试图找到从 1 到 15 的值,其中未定义值在两个数组中。sku[1] 和 mr_sku 我知道是相同的值 - 只是永远不会在数组中显示为 bieng - inarray 总是返回为 -1

4

1 回答 1

0

用虚拟数据测试,它工作正常。这是jsfiddle,这是我使用的数据:

var sku = ['a','b','c'];
var mr_sku = ['a','c','c'];

for (index=1; index<=2; index++) {
    if (undefined != sku[index]) {

        found = jQuery.inArray(sku[index], mr_sku); 
        if( found == -1){ //not in array
            alert( sku[index] + " NOT FOUND - delete index " + index );
        } else { // in array
                  alert("FOUND");
        }

  }
}​
于 2012-09-23T17:40:26.613 回答