Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
 
PREVIOUS NEXT
Tagged: #lodash #find #duplicate #element #index
ADD COMMENT
Topic
Name
2+5 =