How to get duplicate values from an array with JavaScript Lodash?

To get duplicate values from an array with JavaScript Lodash, we can use the filter and includes methods.

For instance, we write

const dups = _.filter(arr, (val, i, iteratee) =>
  _.includes(iteratee, val, i + 1)
);

to call filter with arr and a callback that calls includes to check if val is included in the arr array itself from index i + 1 and oin.

iteratee is the arr array.

An array with the duplicates is returned.