# Iterating through array until item.x is found, then assign item.y as variable

**URL:** <https://community.postman.com/t/iterating-through-array-until-item-x-is-found-then-assign-item-y-as-variable/36299>\
**Category:** Help Hub\
**Tags:** variables, response, array, loop\
**Created:** [June 17, 2022, 9:04am UTC](https://community.postman.com/t/iterating-through-array-until-item-x-is-found-then-assign-item-y-as-variable/36299 "2022-06-17T09:04:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgoorkate](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@sgoorkate](https://community.postman.com/u/sgoorkate)\
**Post date:** [June 17, 2022, 9:04am UTC](https://community.postman.com/t/iterating-through-array-until-item-x-is-found-then-assign-item-y-as-variable/36299/1 "2022-06-17T09:04:15Z")

</div>

Hello. I’m trying to write a test that checks if the response of a GET, an array, contains a certain value (a string). The value that it should be looking for comes from a CSV file, because the request is part of a collection that I want to run. If item.x in the array contains that value, I want to assign item.y to a new collection variable, which I can use in the next request in this collection. It should look something like this (_permissiongroup_ would be the value the comes from the CSV file):

> let getgroups = pm.response.json();
> 
> pm.collectionVariables.set(“group”, getgroups)
> 
> loop through group  
> if group.name = permissiongroup  
> pm.collectionVariables.set(“permissiongroupid”, group.id)

Obviously this doesn’t work, but hopefully you understand what I’m trying to do. Is this even possible? If so, can anyone point me in the right direction? Thanks in advance!
