javascript - Filter the nested array based on condition -


i have object this:

runs =      {         "suites": [             {                 "status": "fail",                 "testcases": [                     {                         "status": "pass"                     },                     {                         "status": "fail"                     }                 ]             },             {                 "status": "pass",                 "testcases": [                     {                         "status": "pass"                     }                 ]             }         ]     } 

i retrieve count of test case pass , fail (in above case pass: 2, fail: 1). tried following pass count:

runs.suites.filter(suite => {     suite.testcases.filter(testcase => {         return testcase.status === 'pass';     }) }).length 

but giving me incorrect result.

try this

// code goes here      runs =          {             "suites": [                 {                     "status": "fail",                     "testcases": [                         {                             "status": "pass"                         },                         {                             "status": "fail"                         }                     ]                 },                 {                     "status": "pass",                     "testcases": [                         {                             "status": "pass"                         }                     ]                 }             ]         };         var count = 0;         var test = runs.suites.filter(suite => {             suite.testcases.filter(testcase => {                 (testcase.status=='pass')?count++:count;             })             return count;         });      console.log(test.length); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -