你可以使用 JavaScript 的数组方法 some()
来判断两个数组中是否含有相同的值。
这是一个例子:
function hasCommonValue(arr1, arr2) {
return arr1.some(function(value) {
return arr2.includes(value);
});
}
console.log(hasCommonValue([1, 2, 3], [4, 5, 6])); // false
console.log(hasCommonValue([1, 2, 3], [4, 5, 2])); // tru