filter deep nested property returns empty array

80 Views Asked by At

I have array of objects

var data = [{type:"A",parentPersonInfo:{id:1,fullname:'john smith'}},{type:"A",parentPersonInfo:   {id:1,fullname:'jim smith'}},{type:"B",parentPersonInfo:   {id:2,fullname:'jane smith'}}]

I want to use lodash to extract the records where type = A and id = 1

const testId = 1;
_.filter(data,{'type':'A','data.parentPersonInfo.id':1});

but i get []

1

There are 1 best solutions below

0
JesusTinoco On BEST ANSWER

Could you check if using the code below works?

_.filter(data, {type: 'A', parentPersonInfo: {id:1}});