Help with parsing and setting an environment variable

Hi, Can anyone help me and provide the tests script to parse the first item of many in an API response message? I am trying to parse the 1st element value called itineraryId in this API response message and save it to an environment variable but having difficulty. I am able to parse the Search ID item successfully but the sub item of Itinerary ID is causing me issues.

Sample API response message:
{
“searchId”: “XXXXXXXXXXXXI=”,
“itineraryDetails”: {
“itineraries”: [
{
“itineraryId”: “CicKJQoQYmNkYmFlNzU0YmRmYTc0YhIPCA4SATEYASIGCgRMQTVLIAE=”,

I’ve already tried*:
This for the Search ID and it works but not sure how to parse and save the 1st Itinerary ID to a environment file object.

var jsonData = JSON.parse(responseBody);

postman.setEnvironmentVariable(“Search ID”, jsonData.searchId);

Itineraries is an array so you need to include the array index (array indexes start at zero).

const response = pm.response.json();
console.log(response);

let itinerary = response.itineraryDetails.itineraries[0].itineraryId
console.log(itinerary);

pm.environment.set("itineraryId", itinerary);
console.log(pm.environment.get("itineraryId"));

@michaelderekjones Thanks so much for the help, that code works and has resolved my question.