Search code examples
javascriptlodashecmascript-harmony

filter deep nested property returns empty array


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 []


Solution

  • Could you check if using the code below works?

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