检查订阅angular10中是否存在数组值



我有一些常量数组值,我在subscribe中有响应值,我想检查常量数组值是否在响应中可用。我不知道如何在subscribe中使用map和filter。如果这个值是可用的,那么checkval应该返回true或false。我可以使用一些函数,但这里我需要使用rxjs运算符

Response:
{
"testLoad": 1603367083993,
"checkData": "test1"
"type": "flag",
"title": "TestFlag",
"styleId": "test",
"BodyContent": {
"properties": "undefined"
}
}

const styleid: Array<string> = ['test1','test2','test3'];
public checkVal(){
this.idVal =this.data.getresponse().subscribe((response => console.log(response ));
}

由于我是angular rxjs的新手,你能指导我并帮助我解决这个问题吗

根据我所理解的注释,如果response.checkData值包含在pageUid数组中,则您希望返回一个trueObservable。

您可以执行以下操作:

this.data.getresponse().pipe(
map(response => pageUid.includes(response.checkData)),
).subscribe(checkResult => console.log(checkResult));

最新更新