Created
May 30, 2022 09:54
-
-
Save S-codes14/9a1d9baf1d4a1169285ece66bda273d8 to your computer and use it in GitHub Desktop.
How to compare two arrays in javascript and then output return array of missing
This file contains hidden or 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
var ArrayFileName = ['one', 'two', 'three', 'three', 'five', 'six', 'ten']; | |
var ArrayFileName2 = ['one', 'two', 'three', 'ten', 'eleven']; | |
var final = ArrayFileName2.filter(function(item) { | |
for (var i = 0; i < ArrayFileName.length; i++) { | |
if (ArrayFileName[i] === item) return false; | |
} | |
return true; | |
}) | |
console.log(final); // ['eleven'] | |
var final2 = ArrayFileName.filter(function(item) { | |
for (var i = 0; i < ArrayFileName2.length; i++) { | |
if (ArrayFileName2[i] === item) return false; | |
} | |
return true; | |
}) | |
console.log(final2) //['five', 'six'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment