lodash find duplicate code example

Example 1: Lodash remove duplicates from array

var users = [
  {id:1,name:'ted'},
  {id:1,name:'ted'},
  {id:1,name:'bob'},
  {id:3,name:'sara'}
];
var uniqueUsersByID = _.uniqBy(users,'id'); //removed if had duplicate id
var uniqueUsers = _.uniqWith(users, _.isEqual);//removed complete duplicates

Example 2: lodash find duplicate element index

const _ = require('lodash');
let arr = ["a", "a", "b", "c", "c", "a"];

let result = _.omitBy(
  _.reduce(arr, (a, v, i) => _.set(a, v, (a[v] || []).concat([i])), {} ),
  v => v.length <= 1
);

console.log(result);