Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  21] [ 7]  / answers: 1 / hits: 97819  / 11 Years ago, thu, june 13, 2013, 12:00:00

Consider this example. I am using Lodash



 'data': [
{
'category': {
'uri': '/categories/0b092e7c-4d2c-4eba-8c4e-80937c9e483d',
'parent': 'Food',
'name': 'Costco'
},
'amount': '15.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'India Bazaar'
},
'amount': '10.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'Sprouts'
},
'amount': '11.1',
'debit': true
},


When I do



_.filter(summary.data, {'debit': true})


I get all the objects back.



what I want?



I want all the objects where category.parent == 'Food', how can I do that?



I tried



_.filter(summary.data, {'category.parent': 'Food'})


and got



[]

More From » lodash

 Answers
18
_.filter(summary.data, function(item){
return item.category.parent === 'Food';
});

[#77632] Wednesday, June 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;