I have a problem in Node.js.. My problem is two arrays comparing. For example;
My original array is;
var a = ["1","2","3","4","5"];
and the other array is;
var b = ["3","1","4","6","8","7"];
so, result message what I want is: "2 and 5 is missing the original array.."
So how can I get this message after comparison of two arrays?
Use Array#filter
method to filter array elements.
var a = ["1", "2", "3", "4", "5"];
var b = ["3", "1", "4", "6", "8", "7"];
console.log(
a.filter(function(v) {
return !b.includes(v);
})
)
// or for older browser
console.log(
a.filter(function(v) {
return b.indexOf(v) == -1;
})
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With