# Loop through response array multiple objects to find if value of each object is within(or equal) to parameters given in request

**URL:** <https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [December 23, 2021, 11:39am UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978 "2021-12-23T11:39:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergeyor](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sergeyor](https://community.postman.com/u/sergeyor)\
**Post date:** [December 23, 2021, 11:39am UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978/1 "2021-12-23T11:39:30Z")

</div>

_My question_:  
I have request with parameters (image 1)  
I 'am getting response with array with multiple objects . I need test to go through and check if each object have value between or equal to values in request.  
My final goal is to create pm.test where I can check that all of objects are inside those values  
response - images -2,3  
Thank you

_Details (like screenshots)_:  
1 - ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/5/b5473c728f7d55b99a5373177981dde95b502716.png)  
2 -

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

_How I found the problem_:

_I’ve already tried_:

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [December 23, 2021, 12:57pm UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978/2 "2021-12-23T12:57:01Z")

</div>

hey @sergeyor 👋 Welcome to the community 🥳

So the request which gives you the parameters, ‘orgUnitFrom’ and ‘orgUnitTo’ you can either save these value to the Collection or Environment variables to use them later in another request or you can just copy these value and use in your Test function.

In the request where you have the array of objects, just run a loop and check for ‘orgUnit’ to be between the parameter, one way you can do this is:

```auto
let response=pm.response.json()

let orgUnitFrom= 390101020  

let orgUnitTo= 390102101

//you can also store those value in Environment or Collection variables in 
//first request and retrieve them here
//pm.collectionVariables.get("orgUnitFrom") 
// pm.environment.get("orgUnitFrom")

pm.test("Unit check",()=>{
    _.each(response.results, (item)=>{
       // console.log(orgUnitFrom,item.orgUnit,orgUnitTo)
        pm.expect(orgUnitFrom<=item.orgUnit?true:false).eqls(true)
        pm.expect(orgUnitTo>=item.orgUnit?true:false).eqls(true)
    })
})

```

Hope this helps,  
Good luck!

---

<div class="post-metadata">

**Author:** ![sergeyor](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sergeyor](https://community.postman.com/u/sergeyor)\
**Post date:** [December 23, 2021, 1:13pm UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978/3 "2021-12-23T13:13:20Z")

</div>

Hi @bbahadur  
Thank you for reply  
If I understand correctly the pm.test only check if response values are equal to request values  
but response have also values between those two values.  
Can your test also check for those between values?

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [December 23, 2021, 1:25pm UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978/4 "2021-12-23T13:25:26Z")

</div>

The lines

```auto
 pm.expect(orgUnitFrom<=item.orgUnit?true:false).eqls(true)
 pm.expect(orgUnitTo>=item.orgUnit?true:false).eqls(true)

```

will check each response values to be between those values, also also if they are equal.

---

<div class="post-metadata">

**Author:** ![sergeyor](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sergeyor](https://community.postman.com/u/sergeyor)\
**Post date:** [December 26, 2021, 1:04pm UTC](https://community.postman.com/t/loop-through-response-array-multiple-objects-to-find-if-value-of-each-object-is-within-or-equal-to-parameters-given-in-request/30978/5 "2021-12-26T13:04:29Z")

</div>

It’s working  
Thank you very much
