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

问题描述

我有一些const数组值,我在subscribe中有响应值,我想检查const数组值是否在响应中可用。我不知道如何在订阅中使用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还是新手,请您指导我并帮助解决此问题

解决方法

根据我的评论,如果true数组中包含response.checkData值,您想返回一个pageUid可观察值。

您可以执行以下操作:

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