# POST Response Assertion to search through all ITEM.s to return a value if found

**URL:** <https://community.postman.com/t/post-response-assertion-to-search-through-all-item-s-to-return-a-value-if-found/41537>\
**Category:** Help Hub\
**Tags:** responseassertion\
**Created:** [November 28, 2022, 5:42pm UTC](https://community.postman.com/t/post-response-assertion-to-search-through-all-item-s-to-return-a-value-if-found/41537 "2022-11-28T17:42:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanHamilton00](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ryanhamilton00/32/11087_2.png) [@RyanHamilton00](https://community.postman.com/u/RyanHamilton00)\
**Post date:** [November 28, 2022, 5:42pm UTC](https://community.postman.com/t/post-response-assertion-to-search-through-all-item-s-to-return-a-value-if-found/41537/1 "2022-11-28T17:42:46Z")

</div>

_My question_: I am trying to validate a POST Response, I get many results and I just want to confirm if the value exists and move on. I suspect this is an often-wanted assertion so I am pretty confident I am making it too hard or flat-out misunderstanding.

_Details (like screenshots)_:  
My Response is 2000 lines long and I want to search for a specific ITEM in the response, the ITEM response is an array and I just want it to cycle/loop through the ITEM and find a value:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/a/0a00cec15b931b9bfce88a0aa734f7d8bd5e477e.png)

Error:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/8/88206be2f25b69a9c0862ac7d4f6e7a3eaa68bfb.png)

_I’ve already tried_:  
I have been trying a variation from another help topic on this forum with no luck but here is my assertion:

var CourseId1 = pm.globals.get(“gCourseId1”);  
let jsonData = pm.response.json();

pm.test("Verify Course was added to requiredCourseDetailList from courseCategoryDetailList1: " + CourseId1, () =\> {  
let requiredCourseId = \_.values(jsonData[‘payload’].data.requiredCourseDetailList);  
console.log(requiredCourseId);  
\_.each(requiredCourseId, (item) =\> {pm.expect(item.requiredCourseId).to.equal(CourseId1);  
});  
});

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 29, 2022, 1:04pm UTC](https://community.postman.com/t/post-response-assertion-to-search-through-all-item-s-to-return-a-value-if-found/41537/2 "2022-11-29T13:04:09Z")

</div>

Postman uses JavaScript under the hood.

There are two main methods for searching arrays, and this is via “find” and “map”.

If you could provide a sample JSON file with 3 entries under the course detail list, I can probably provide an example using one of the methods detailed above.

You should be able to find the required course that equals a particular number, and also include some of the other fields to help with the assertion.

---

<div class="post-metadata">

**Author:** ![RyanHamilton00](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/ryanhamilton00/32/11087_2.png) [@RyanHamilton00](https://community.postman.com/u/RyanHamilton00)\
**Post date:** [November 30, 2022, 3:59pm UTC](https://community.postman.com/t/post-response-assertion-to-search-through-all-item-s-to-return-a-value-if-found/41537/3 "2022-11-30T15:59:52Z")

</div>

I was able to figure it out using the following:

var jsonData = pm.response.json();  
var requiredCourseId = jsonData.payload.data.requiredCourseDetailList.map((i) =\> i.requiredCourseId);  
pm.test("The requiredCourseDetailList contains the correct course: " + CourseId1, function () {  
pm.expect(requiredCourseId.includes(CourseId1)).to.eql(true);  
});
