Extracting variable from response array based on another value

I am trying to pull “PracticeID” from the response array (see below) where PracticeCode = “FOVF”

I know I can use [1] to get the second object in the array like the script below, BUT our test systems don’t always have FOVF in the second array object.

Thanks!

Current script:
var authorizedPractices = JSON.parse(responseBody);
postman.setEnvironmentVariable(“PracticeID”, authorizedPractices.UserPracticeList[1].PracticeID);

My Response:
{

"ErrorCode": "",

"ErrorMessage": "",

"UserPracticeList": [

    {

        "PracticeID": 132528,

        "PracticeCode": "BNUM",

        "PracticeName": "Flagler Health"

    },

    {

        "PracticeID": 16,

        "PracticeCode": "FOVF",

        "PracticeName": "Simpson, Moore and Moore"

    },

    {

        "PracticeID": 7,

        "PracticeCode": "OFC",

        "PracticeName": "Eastside Urgent Care"

    },

    {

        "PracticeID": 13,

        "PracticeCode": "QVSR",

        "PracticeName": "Paine and Associates"

    },

    {

        "PracticeID": 19,

        "PracticeCode": "YULE",

        "PracticeName": "Southside Pediatrics"

    }

]

}

I think I figured it out!

authorizedPractices = JSON.parse(responseBody);

for(var i = 0; i < authorizedPractices.UserPracticeList.length; i++)
{
  if(authorizedPractices.UserPracticeList[i].PracticeCode == 'FOVF')
  {
    postman.setEnvironmentVariable("PracticeID", authorizedPractices.UserPracticeList[i].PracticeID);
  }
}