JSFiddle - React, Tailwind, and code Playground
by Hugo Carneiro
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
JavaScript
var layouts = [
{
id: 1,
title: 'Hello',
settings: {
tags: ['new', 'popular']
}
},
{
id: 2,
title: 'World',
settings: {
tags: ['new', 'layouts']
}
}
];
var tags = _.chain(layouts)
.map((layout) => {
var layoutTags = _.get(layout, 'settings.tags', [])
return layoutTags
})
.concat()
.flatten()
.uniq()
.orderBy()
.concat(['All'])
.value();
/* _.flatten([].concat(_.map(layouts, (layout) => {
var layoutTags = _.get(layout, 'settings.tags', [])
return layoutTags
}))); */
console.log(tags)