I am attempting to build an array of unique values pulled from an array of objects. Here is the data structure:
data: [
{
"tags": [
{
"name": "tag",
"value": "Bold"
},
{
"name": "tag",
"value": "Crazy"
},
{
"name": "tag",
"value": "Colorful"
},
{
"name": "tag",
"value": "Smooth"
}
],
"rating": 5,
"userNickName": "lookinGood",
"userLocation": "USA",
"title": "LOVE IT",
"reviewText": "Blah blah blah",
"submissionTime": "14 January 2013"
},
{
"tags": [
{
"name": "tag",
"value": "Colorful"
},
{
"name": "tag",
"value": "Too bright"
}
],
"rating": 4,
"userNickName": "CrazyColors",
"userLocation": "USA",
"title": "Kept It",
"reviewText": "Hoopity hoo blah",
"submissionTime": "13 December 2014"
}
]
Here is what my code looks like so far:
let tags: Array<string> = _.sortBy(
_.uniq(
this.props.reviewData.reviews.map(
(o) => {
return o.tags && o.tags.value ? o.tags.value.trim() : '';
}
)
)
);
But tags keeps coming through blank. I've also tried return _.map(v.tags, 'value') but that returns multiple arrays. So how can I grab one of each tag value from multiple objects?