recursion - Javascript recursive search -


i'm having trouble recursive search. want return block id found in.

this data:

{ "rows": [{     "columns": [{         "id": "ie1ymsahu",         "rows": [{             "columns": [{                 "id": "vjbjvrfp"             }, {                 "id": "njb1234a",                 "rows": [{                     "columns": [{                         "id": "vjbjvxxx"                     }, {                         "id": "njb1234b"                     }]                 }]             }]         }]     }, {         "id": "ejnasd-v",         "rows": [{             "columns": [{                 "id": "vjbjvyyy"             }]         }]     }] }] } 

it should returning

    {         "id": "ejnasd-v",         "rows": [{             "columns": [{                 "id": "vjbjvyyy"             }]         }]     } 

but instead it's returning false. here's code:

function findcolumnwithid(obj, id){     for(var = 0; < obj['rows'].length; i++){         for(var j = 0; j < obj['rows'][i]['columns'].length; j++){             if(obj['rows'][i]['columns'][j].id == id)                 return obj;              if(obj['rows'][i]['columns'][j].hasownproperty('rows')){                 var result = findcolumnwithid(obj['rows'][i]['columns'][j], id);                  if(typeof result !== false)                     return result;             }         }     }      return false; }  findcolumnwithid(data, 'vjbjvyyy'); 

i'm not sure what's going on. doesn't seem iterating on last part of json data. code work in 5 out of 6 use cases, makes more strange. appreciated.

removing 'typeof' in if statement fixes code.

if(typeof result !== false) 

Comments