JSFiddle - React, Tailwind, and code Playground
by Hugo Carneiro
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>
JavaScript
var data = {
title: 'Something',
labels: [
{
label: 'Copy',
action: {
type: 'toCopy',
text: 'Something else'
}
},
{
label: 'Edit',
action: function(i) {
console.log('here');
}
},
]
};
var buttonLabels = _.map(data.labels, function(label) {
return _.pick(label, ['label', 'action']);
});
var result = _.flatMap(data.labels, function (item) {
var label = item.label;
var action = _.pick(item.action, ['type', 'text']);
return _.assign({ label: label }, action);
});
console.log(result);