How To Find Child Object With Property Value Using Underscorejs And Jquery?
Take the following data: object { name: 'foo' children: [ { 'name': 'cat' 'color': 'green' }, { 'name': 'dog' 'color': '
Solution 1:
In JQuery you can use filter to get the child object.
var obj = {
name: 'foo',
children: [
{
'name': 'cat',
'color': 'green'
},
{
'name': 'dog',
'color': 'blue'
},
{
'name': 'bird',
'color': 'red'
}
]
};
console.log(obj.children.filter(function(e){return e.name == "dog";})[0]);
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Post a Comment for "How To Find Child Object With Property Value Using Underscorejs And Jquery?"