Created
January 9, 2018 04:26
-
-
Save sekky0905/bf74de83bd8a63f32f0adacd8ffc520e to your computer and use it in GitHub Desktop.
JavaScriptで2つの配列の差分を抽出する ref: https://qiita.com/Sekky0905/items/c9c063a826cb4322ced4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array1に含まれていて、array2に含まれていない : 1 | |
array1に含まれていなくて、array2に含まれていてる : 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment