const arr1 = [1, 4, 5, 6, 7] const arr2 = [12, 3, 4, 7, 65] const arr3 = [4, 6, 2, 4, 1, 7] const fn = (...args) => { let res = args[0] for(let j = 1; j < args.length; j++){ const arr = args[j] res = res.filter(item => arr.includes(item)) } return res } console.log(fn(arr1, arr2, arr3))