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

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!