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
Post a Comment