0
想不通爲什麼總是返回false:在運營商總是返回false
var filter_clients = [25,351];
var data = 351;
console.log(filter_clients);
console.log(data);
if(data in filter_clients) console.log('in');
else console.log('out');
想不通爲什麼總是返回false:在運營商總是返回false
var filter_clients = [25,351];
var data = 351;
console.log(filter_clients);
console.log(data);
if(data in filter_clients) console.log('in');
else console.log('out');
使用數組時,in
操作適用於指數,而不是價值。例子:
0 in filter_clients //true
1 in filter_clients //true
2 in filter_clients //false
這是實現你試圖做
filter_clients.indexOf(data) != -1
這可以解釋它有什麼辦法。謝謝 –