Skip to content

Instantly share code, notes, and snippets.

@danielt69
Created July 31, 2018 07:34
Show Gist options
  • Select an option

  • Save danielt69/3cca1ad406230e0350d82d26a848b2ac to your computer and use it in GitHub Desktop.

Select an option

Save danielt69/3cca1ad406230e0350d82d26a848b2ac to your computer and use it in GitHub Desktop.
Difference Between 2 JavaScript Arrays
Array.prototype.diff = function (a) {
return this.filter(function (i) {
return a.indexOf(i) === -1;
});
};
// usage:
[1, 2, 3, 4, 5, 6].diff([2, 4, 6]);
// => [1, 3, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment