好的,可以使用 JavaScript 中的 filter 函数来过滤出两个数组中的相同值。
具体的实现方法是,你需要定义一个 callback 函数,在该函数中判断某个元素是否存在于另一个数组中。然后在第一个数组上使用 filter 函数,传入这个 callback 函数。
例如,你可以这样写:
const array1 = [1, 2, 3, 4];
const array2 = [3, 4, 5, 6];
const commonValues = array1.filter(value => array2.includes(value));
console.log(com