javascript - Nested array is not returning deepest obj -


i working lodash, trying obtain object nested in array. need bettypes, put var needdeepestobj bettypes using _.filter

var deepestobj = function(betslipdata) {    var needdeepestobj =       _.filter(betslipdata.customerbettypes, function(betindex) {       return _.filter(betindex.bettypes, function(bettypes) {          console.log('1', bettypes); //returns need          return bettypes;       });     });      console.log('2', needdeepestobj);    //returns first _.filter param *betindex* }; 

so, how can reach scope contains bettypes ?

this betindex param returns in browser console.

{   "header": {     "name": "straights",     "priority": "1"   },   "bettypes": [     {       "id": "1",       "name": "straight",       "buypoints": "y",       "maxpoints": "3",       "minpoints": "0",       "isavailable": "1",       "placebetisavailable": "1",       "reasonplacebetnotavailable": "",       "isselected": "0",       "priority": 1     }   ],   "header": {     "name": "straights",     "priority": "1"   },   "bettypes": [     {       "id": "1",       "name": "straight",       "buypoints": "y",       "maxpoints": "3",       "minpoints": "0",       "isavailable": "1",       "placebetisavailable": "1",       "reasonplacebetnotavailable": "",       "isselected": "0",       "priority": 1     }   ],   "header": {     "name": "straights",     "priority": "1"   },   "bettypes": [     {       "id": "1",       "name": "straight",       "buypoints": "y",       "maxpoints": "3",       "minpoints": "0",       "isavailable": "1",       "placebetisavailable": "1",       "reasonplacebetnotavailable": "",       "isselected": "0",       "priority": 1     }   ],   "header": {     "name": "straights",     "priority": "1"   },   "bettypes": [     {       "id": "1",       "name": "straight",       "buypoints": "y",       "maxpoints": "3",       "minpoints": "0",       "isavailable": "1",       "placebetisavailable": "1",       "reasonplacebetnotavailable": "",       "isselected": "0",       "priority": 1     }   ] } 

so, need bettypes, , betindex returns json pasted above.

update

obviously, big json, contains thousand "header" , "bettypes" properties. need iterate on json in order process once properties.

i'm not sure if follow question exactly. answer under assumption thatl:

betslipdata.customerbettypes = [{ header: {}, bettypes: [{}] }, ...] 

then it's simple:

var needdeepestobj = _(betslipdata.customerbettypes).map(function (bet) {     return bet.bettypes; }).flatten().value(); 

this produce array of objects each array of bettypes within each bet.

it lot if show example of betslipdata.customerbettypes , exact result looking for, whether it's array or object, specific keys, etc.

are looking specific bettype?


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -