How does JS take out the different values of two arrays and synthesize a new array

for example

var array1 = [ 5,9,8,10,55];
var array2 = [ 5,50,10];
var arr3=[9,8,55,50]
Nov.20,2021

the idea is as follows:

1, take the difference between two arrays

var array1 = [ 5,9,8,10,55];
var array2 = [ 5,50,10];
const newArray = (arr1, arr2) =>{
  return [...arr1.filter(x=> !arr2.includes(x)), ...arr2.filter(x=> !arr1.includes(x))]
} 
Menu