differenceBy source npm

_.differenceBy(array, [values], [iteratee=_.identity])

This method is like _.difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which uniqueness is computed. The iteratee is invoked with one argument: (value).

Arguments

  1. array (Array)

    The array to inspect.

  2. [values] (...Array)

    The values to exclude.

  3. [iteratee=_.identity] (Function|Object|string)

    The function invoked per element.

Returns (Array)

Returns the new array of filtered values.

Example

_.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
// => [3.1, 1.3]

// using the `_.property` callback shorthand
_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
// => [{ 'x': 2 }]