Find diff of two []s
Difference between two arrays in native JS.
by Superman
JavaScript
var foo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
var bar = [1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 24, 26, 27, 28, 29, 30];
var baz = [];
foo.forEach(function(key) {
if (-1 === bar.indexOf(key)) {
baz.push(key);
}
}, this);
console.log("foo: "+foo);
console.log("bar: "+bar);
console.log("baz: "+baz);