Say I have an array like this: [1, 1, 2, 2, 3]
I want to get the duplicates which are in this case: [1, 2]
Does lodash support thi
Here is another concise solution:
let data = [1, 1, 2, 2, 3]
let result = _.uniq(_.filter(data, (v, i, a) => a.indexOf(v) !== i))
console.log(result)
_.uniq
takes care of the dubs which _.filter
comes back with.
Same with ES6 and Set:
let data = [1, 1, 2, 2, 3]
let result = new Set(data.filter((v, i, a) => a.indexOf(v) !== i))
console.log(Array.from(result))