I'm using lodash and I have an array:
const arr = ['firstname', 'lastname', 'initials', 'initials'];
I want a new array containing only the values that appear more than once (the duplicate values).
It seems like this is something lodash might have a specific method for, but I can't see one. Something like: const dups = _.duplicates(arr);
would be nice.
I've got:
// object with array values and number of occurrences
const counts = _.countBy(arr, value => value);
// reduce object to only those with more than 1 occurrence
const dups = _.pickBy(counts, value => (value > 1));
// just the keys
const keys = _.keys(dups);
console.log(keys); // ['initials']
Is there a better way than this..?