I'm trying to remove duplicate items using lodash.js but I can't make it works properly.
This is the structure of an object in the array:
{
label: 'tagA',
value: 1
}
So let say I have this array:
var objectsArray = [
{
label: 'tagA',
value: 1
},
{
label: 'tagB',
value: 2
},
{
label: 'tagC',
value: 3
},
{
label: 'tagB',
value: 4
},
{
label: 'tagB',
value: 5
},
];
I made this piece of code with _.uniqBy() function from lodash.js to try to remove the elements of array with the same labels, but it dosn't work as I expected:
var uniq = _.uniqBy(objectsArray, function(o){
return o.label;
});
I based on some sample found here and there and lodash documentation of course but I have a lack of knowledge in this regard so any help it will super appreciate it.
Thanks.