diff --git a/src/libs/tools.js b/src/libs/tools.js index 0ca81d61f..bf3437077 100644 --- a/src/libs/tools.js +++ b/src/libs/tools.js @@ -14,12 +14,13 @@ export const forEach = (arr, fn) => { * @description 得到两个数组的交集, 两个数组的元素为数值或字符串 */ export const getIntersection = (arr1, arr2) => { - let len = Math.min(arr1.length, arr2.length) + if (!arr1.length || !arr2.length) return [] + let len = arr1.length let i = -1 let res = [] while (++i < len) { - const item = arr2[i] - if (arr1.indexOf(item) > -1) res.push(item) + const item = arr1[i] + if (arr2.indexOf(item) > -1) res.push(item) } return res }