答案 0 :(得分:6)
if(listCategoryId.indexOf(actualCategoryId) != -1) {
console.log('exists')
}
答案 1 :(得分:2)
如果Array.prototype.indexOf()
返回大于或等于0的索引,则该数组包含指定的元素。否则它将返回-1:
var hideFilters = function() {
var listCategoryId = ['1000014', '1000015', '1000016', '1000017', '1000018', '1000019', '1000021', '1000086'];
var actualCategoryId = '1000018';
if (listCategoryId.indexOf(actualCategoryId) > -1) {
console.log('is equal');
} else {
console.log('fuen... fuen...');
}
};
hideFilters();

答案 2 :(得分:1)
您可以使用 $.inArray
var listCategoryId = ['1000014', '1000015', '1000016', '1000017', '1000018', '1000019', '1000021', '1000086'];
var actualCategoryId = '1000018';
if ($.inArray(actualCategoryId, listCategoryId) != -1) {
console.log('exists');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>