Skip to content

Instantly share code, notes, and snippets.

@sekky0905
Created January 9, 2018 04:26
Show Gist options
  • Save sekky0905/bf74de83bd8a63f32f0adacd8ffc520e to your computer and use it in GitHub Desktop.
Save sekky0905/bf74de83bd8a63f32f0adacd8ffc520e to your computer and use it in GitHub Desktop.
JavaScriptで2つの配列の差分を抽出する ref: https://qiita.com/Sekky0905/items/c9c063a826cb4322ced4
const array1 = [0, 1, 2, 3, 4];
const array2 = [0, 6, 2, 3, 4];
array1.concat(array2)
.forEach(item => {
if (array1.includes(item) && !array2.includes(item)) {
console.log(`array1に含まれていて、array2に含まれていない : ${item}`);
} else if (!array1.includes(item) && array2.includes(item)) {
console.log(`array1に含まれていなくて、array2に含まれていてる : ${item}`);
}
})
array1に含まれていて、array2に含まれていない : 1
array1に含まれていなくて、array2に含まれていてる : 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment