# If condition comparing response value with the Collection variable in an array

**URL:** <https://community.postman.com/t/if-condition-comparing-response-value-with-the-collection-variable-in-an-array/29519>\
**Category:** Help Hub\
**Created:** [November 9, 2021, 6:05am UTC](https://community.postman.com/t/if-condition-comparing-response-value-with-the-collection-variable-in-an-array/29519 "2021-11-09T06:05:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aerospace-geoscient7](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@aerospace-geoscient7](https://community.postman.com/u/aerospace-geoscient7)\
**Post date:** [November 9, 2021, 6:05am UTC](https://community.postman.com/t/if-condition-comparing-response-value-with-the-collection-variable-in-an-array/29519/1 "2021-11-09T06:05:43Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.  
> My Question:

1. I want to assert “FP”: “FOP2”. - Completed
2. And If 1st step is success. I want to Assert “SMO”: false, - Completed
3. And also I need to Assert SP.name.FOP2 and its corresponding Exam.“Marksguid”: “f778dd51-d401-42ca-a5ea-4920db5708b2”, - Completed
4. If I’m comparing if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable)

This is the API JSON Response

[{  
“FP”: “DAV1”,  
“SMO”: false,  
“SP”: [{  
“name”: “FOP1”,  
“Exam”: [{  
“Marksguid”: “a02dac4f-630f-4ed0-aa54-8c7044b71f2f”,  
“apiUrl”: “test1”,  
“interval”: 65,  
“schemaVersion”: “1.2”,  
“authenticationType”: “Basic”  
}]  
}]  
}, {  
“FP”: “FOP10”,  
“SMO”: false,  
“SP”: [{  
“name”: “FOP10”,  
“Exam”: [{  
“Marksguid”: “f778dd51-d401-42ca-a5ea-4920db5708b2”,  
“apiUrl”: “test1”,  
“interval”: 65,  
“schemaVersion”: “1.2”,  
“authenticationType”: “Basic”

}]  
}]  
}]

The below Script is working fine for picking the value one of my friend in this community helped me (Bbahadur).  
Now if I’m want to compare if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable).  
I ahd FOP2 value in a collection variable now I want to compare if(item.FP==Collectionvariable) I used get collection variable syntax but still it throws undefined

pm.test(‘Assertions’, () =\> {  
var FP\_exists; // a variable in which we will save the required FP from response if it exists  
\_.each(jsonData, (item) =\> {  
if(item.FP==“FOP10”)  
pm.expect(item.SMO).to.eql(false)

if(item.FP==“testnorecords”)  
FP\_exists=item.FP;  
})  
//after looping through all objets, we check if the required FP value exists or not  
pm.test(“testnorecords exists”,()=\>{  
pm.expect(FP\_exists).to.eql(“testnorecords”);  
})  
})

_My question_:  
The above Script is working fine for picking the value one of my friend in this community helped me (Bbahadur).  
Now if I’m want to compare if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable).  
I ahd FOP2 value in a collection variable now I want to compare if(item.FP==Collectionvariable) I used get collection variable syntax but still it throws undefined

_Details (like screenshots)_:

_How I found the problem_:

_I’ve already tried_:
