您即将离开腾讯云开发者社区,请注意您的账号财产安全
https://ramdajs.com/repl/#?const mq =
{
resourceType: 'QuestionnaireResponse',
item: [
{
linkId: 'Floors',
answer: []
},
{
linkId: 'KID',
answer: [
{
valueBoolean: false
}
]
},
{
linkId: 'Age',
answer: [
{
valueString: '≥30 Years'
}
]
},
{
linkId: 'UnicornGroup',
item: [
{
linkId: 'DoYouLikeUnicorns',
answer: [{valueBoolean: true}]
},
{
linkId: 'DoYouLikeFHIR'
}
],
answer: []
}
]
}
let fItems = mq.item;
console.log('before filtering ', fItems);
var res = fItems.filter(function f(o) {
if (o.answer && o.answer.length > 0) {
return true
} else {
if(o.item){
return f(o.item);
}
}
});
console.log('after filtering ', res);