how to delete the duplicate value from the array.
var list =[1,1,5,5,4,9]
my result will be
var list =[4,9]
how can I do by using lodash
You could check the index and last index of the actual value.
var list = [1, 1, 5, 5, 4, 9],
result = list.filter((v, _, a) => a.indexOf(v) === a.lastIndexOf(v));
console.log(result);
You can do
var list =[1,1,5,5,4,9];
let result = list.reduce((a, b) =>{
a[b] = a[b] || 0;
a[b]++;
return a;
}, []).map((e, idx) => e==1? idx: undefined).filter(e => e);
console.log(result);
you could use _.uniqBy()
_.uniqBy(list ,function(m){
return list.indexOf(m) === list.lastIndexOf(m)
})
_.uniqBy
but i need to delete the duplicate value from thelist