I have an object that contains a list of attributes with corresponding attribute values.
Some of the arrays of values have duplicates values that I'd like to remove.
Example
let attributes = [{
"attribute": "Size",
"values": ["S", " S", "M", "L", "L"]
},{
"attribute": "Shape",
"values": ["Square", "Round", "Square", " Square", " Square"]
}]
let filtered_attributes = attributes.forEach(el => {
el.map(a => a.values.trim())
.filter((item, pos, self) => { return self.indexOf(item) === pos })
.sort();
})
Desired Output
[{
"attribute": "Size",
"values": ["L", "M", "S"]
},{
"attribute": "Shape",
"values": ["Round", "Square"]
}]
How can I return a list of unique values (those with whitespace first trimmed) for each object in the array?