I have the following map function to strip each element in the object of their commas if it exists.
var items = ['mum, dad', 'uncle, dad', 'brother, sister'];
var clean = [];
clean = items.filter(function(item) {
return item.split(',');
});
The problem is that I don't get the expected outcome. My clean
output is the same as items
output.
It should be like:
console.log(items) // ['mum, dad', 'uncle, dad', 'brother, sister']
console.log(clean) // ['mum', dad', 'uncle', dad', 'brother', sister']
there is also another point, how can I get the unique values only, as you can see, once they are stipped of their commas, some values are repeated, like dad
, how can I keep only one?