_.difference

Similar to without, but returns the values from array that are not present in the other arrays.

  1. // Underscore/Lodash
  2. console.log(_.difference([1, 2, 3, 4, 5], [5, 2, 10]))
  3. // output: [1, 3, 4]
  4.  
  5. // Native
  6. var arrays = [[1, 2, 3, 4, 5], [5, 2, 10]];
  7. console.log(array.reduce(function(a, b) {
  8. return a.filter(function(value) {
  9. return !b.includes(value);
  10. });
  11. })));
  12. // output: [1, 3, 4]
  13.  
  14. // ES6
  15. let arrays = [[1, 2, 3, 4, 5], [5, 2, 10]];
  16. console.log(arrays.reduce((a, b) => a.filter(c => !b.includes(c))));
  17. // output: [1, 3, 4]

Browser Support for Array.prototype.reduce()

ChromeEdgeFirefoxIEOperaSafari
3.0 ✔9.0 ✔10.5 ✔4.0 ✔