JSFiddle - React, Tailwind, and code Playground
by denbuzze
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
JavaScript
var navigation = [{
'label': 'Profile',
'categories': [{
'id': 'basic',
'name': 'Basic Information'
}, {
'id': 'contact',
'name': 'Contact Information'
}]
}, {
'label': 'Security',
'categories': [{
'id': 'reset',
'name': 'Reset'
}]
}];
var categoryId = 'reset';
// We're trying to create the fastest way to return {'id': 'basic', 'name': 'Basic Information'}
console.log(1, _.find(navigation, {
categories: [
{
id: categoryId
}
]
}, 'categories.id'));
console.log(2, _.find(_.flatten(_.pluck(navigation, 'categories')), {
id: categoryId
}))