Skip to content

Instantly share code, notes, and snippets.

  • Save kenmori/23c5085e98712867018f7a419c9ee7b7 to your computer and use it in GitHub Desktop.
Save kenmori/23c5085e98712867018f7a419c9ee7b7 to your computer and use it in GitHub Desktop.
【JavaScript】2以上の配列の差分を新たな配列として返す方法(array-diff) How to return the difference between two sequences as a new array
const arr = [1, 2, 3, 4, 6]
const arr2 = [1, 2, 3, 4, 5]
const arr3 = [...arr, ...arr2]
const a = []
for (let [i, e] of arr3.entries()) {
if(!arr.includes(e)) a.push(e)
if(!arr2.includes(e)) a.push(e)
}
console.log(a)
//[6, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment