How to check empty array in For loop

I want to verify that user is able to see Modifier and Modifier Options visibility in SectionsCategoriesItems API endpoint response if Modifier is visible and options are invisible.
If modifierOptions are invisible then it will return like “modifieroptions”: [].

Below is my response:

{
    "sessionToken": "f6v2VsO41ogKAAAABQAAAAAAAAAkYmEwNTRhNzctYWIyZC00ZTZkLWJmZTctMzQ0ZjYyMWQyZjFmAQAAAANBQ0cCAAAAA0FDUAYAAAACMTcFAAAAA2VuZwAAAAA.YBEaRJxT24DL0nT_Hmse6vXL9DXwOdDLytIDWdB6PiA",
    "responsesIncluded": "getSectionsCategoriesItems",
    "responses": [
        {
            "getSectionsCategoriesItems": {
                "content": {
                    "sections": [
                        {
                            "id": 731559,
                            "code": "b9c6b0e2-0ea2-4ac5-b22d-4e07a151cbd9",
                            "referenceCode": null,
                            "name": "Flight/Weather Section",
                            "internalName": "Flight/Weather Section",
                            "gridFormat": "",
                            "headerTitle": "<p>Flight/Weather Section</p>\n",
                            "headerBody": "<p>Flight/Weather Section</p>\n",
                            "relatedItemsTitle": null,
                            "iconCode": "i-f-weather-1",
                            "type": "CustomContent",
                            "customAction": "",
                            "url": null,
                            "displayOrder": 0,
                            "infoModules": [
                                "Flights",
                                "Weather"
                            ],
                            "categories": [],
                            "imageUrl": null,
                            "teasers": [],
                            "analyticsTag": null,
                            "hideFromWebValet": false,
                            "hideFromNativeApps": false,
                            "visibleToRooms": null,
                            "isEncryptedUrl": false,
                            "isVisibleToAllRooms": true,
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "sectionOutlets": [],
                            "widgetReferenceCode": null
                        }                       
                    ],
                    "categoryItems": [
                        {
                            "code": "b9310f4c-5e33-4460-8d82-0acce29fac2a",
                            "price": 20,
                            "imageUrl": null,
                            "directContentParameter": null,
                            "type": "Product",
                            "name": "Product Item with Item Modifiers",
                            "shortDescription": null,
                            "longDescription": null,
                            "categoryCode": "58104a1b-d19c-41a2-a77d-6f2688bfd709",
                            "itemCode": "2e2da95e-ecb3-4b2e-b659-6c4ed9209c20",
                            "printEnabled": false,
                            "emailSharingEnable": false,
                            "qrCodeEnabled": false,
                            "promo": false,
                            "directContentType": null,
                            "availabilityPeriod": null,
                            "attributes": [],
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "relatedCategoryItemCodes": null,
                            "modifiers": [
                                {
                                    "name": "Visible Multi Select Item Modifier with Invisible Options",
                                    "code": "1b1211ab-d6b1-489f-a3ff-5cf417f82d52",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": false,
                                    "sortOrder": 2,
                                    "maximumQuantity": null,
                                    "modifierOptions": []
                                },
                                {
                                    "name": "Multi Select Item Modifier",
                                    "code": "753dc005-13ac-4831-a228-7c4b542eab84",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": false,
                                    "sortOrder": 3,
                                    "maximumQuantity": null,
                                    "modifierOptions": [
                                        {
                                            "value": "Option 1",
                                            "code": "dd4bb4e8-ecd4-4504-85a7-bef127d91369",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 1",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        },
                                        {
                                            "value": "Option 2",
                                            "code": "b821b52d-e453-464b-bfc2-5146ff092321",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 2",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        }
                                    ]
                                }
                            ],
                            "analyticsTag": null,
                            "templateTag": null,
                            "buttons": [],
                            "itemImages": [],
                            "posItemCode": null,
                            "isInStock": true,
                            "spaItemCode": null,
                            "sosItemCode": null,
                            "sortOrder": 1
                        },
                        {
                            "code": "d920aa96-5c04-4d77-aee3-70a6294ad3f6",
                            "price": 100,
                            "imageUrl": null,
                            "directContentParameter": null,
                            "type": "Service",
                            "name": "Service Request Item with SOS Item Code",
                            "shortDescription": "<p>Service Request Item with SOS Item Code</p>\r\n",
                            "longDescription": "<p>Service Request Item with SOS Item Code</p>\r\n",
                            "categoryCode": "5ec9fb71-dbf5-4dcd-9f04-17fb5d881e21",
                            "itemCode": "1d27389b-6bfe-4589-a3cd-ecbe6718e834",
                            "printEnabled": false,
                            "emailSharingEnable": false,
                            "qrCodeEnabled": false,
                            "promo": false,
                            "directContentType": null,
                            "availabilityPeriod": null,
                            "attributes": [],
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "relatedCategoryItemCodes": null,
                            "modifiers": [],
                            "analyticsTag": null,
                            "templateTag": null,
                            "buttons": [],
                            "itemImages": [],
                            "posItemCode": null,
                            "isInStock": null,
                            "spaItemCode": null,
                            "sosItemCode": "TestSOSItemCode",
                            "sortOrder": 1
                        },
                        {
                            "code": "1f52146b-99cb-44f0-a401-a933084fa16c",
                            "price": 10,
                            "imageUrl": "https://irisv4neuqaasstore.blob.core.windows.net/fileresources/public/iris/ACG/0a84a110008ca13a1073e7e430fbb0910e239ab3dbbc454993943ad586daf04a.jpg",
                            "directContentParameter": null,
                            "type": "Product",
                            "name": "Breakfast",
                            "shortDescription": "<p>Breakfast</p>\r\n",
                            "longDescription": "<p>Breakfast</p>\r\n",
                            "categoryCode": "76864660-ea10-4120-b7ba-fcc52cb8bc5f",
                            "itemCode": "63ca267a-5075-41f4-937e-a9bca7ff2803",
                            "printEnabled": false,
                            "emailSharingEnable": false,
                            "qrCodeEnabled": false,
                            "promo": false,
                            "directContentType": null,
                            "availabilityPeriod": null,
                            "attributes": [
                                {
                                    "name": "Multi Select Type Item Attribute",
                                    "values": [
                                        "Option 2",
                                        "Option 1"
                                    ]
                                }
                            ],
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "relatedCategoryItemCodes": null,
                            "modifiers": [
                                {
                                    "name": "Multi Select Item Modifier",
                                    "code": "753dc005-13ac-4831-a228-7c4b542eab84",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": true,
                                    "sortOrder": 0,
                                    "maximumQuantity": null,
                                    "modifierOptions": [
                                        {
                                            "value": "Option 1",
                                            "code": "dd4bb4e8-ecd4-4504-85a7-bef127d91369",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 1",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        },
                                        {
                                            "value": "Option 2",
                                            "code": "b821b52d-e453-464b-bfc2-5146ff092321",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 2",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        }
                                    ]
                                },
                                {
                                    "name": "Multi Select Item Modifier with Maximum Quantity",
                                    "code": "e8191c90-e3b8-4f82-8010-28d7035eedc4",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": false,
                                    "sortOrder": 1,
                                    "maximumQuantity": 10,
                                    "modifierOptions": [
                                        {
                                            "value": "Option 1",
                                            "code": "05955a98-624e-498e-9889-2fd55ce07349",
                                            "price": 0,
                                            "modifierOptionCode": "e8191c90-e3b8-4f82-8010-28d7035eedc4",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 1",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        },
                                        {
                                            "value": "Option 2",
                                            "code": "c69ff093-51df-42ae-99f6-8ea54cc65b5a",
                                            "price": 0,
                                            "modifierOptionCode": "e8191c90-e3b8-4f82-8010-28d7035eedc4",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 2",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        },
                                        {
                                            "value": "Option 3",
                                            "code": "b35a2c94-ddd1-482d-a5ed-2f39d3a51a29",
                                            "price": 0,
                                            "modifierOptionCode": "e8191c90-e3b8-4f82-8010-28d7035eedc4",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 3",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        }
                                    ]
                                }
                            ],
                            "analyticsTag": null,
                            "templateTag": null,
                            "buttons": [],
                            "itemImages": [
                                {
                                    "url": "https://irisv4neuqaasstore.blob.core.windows.net/fileresources/public/iris/ACG/0a84a110008ca13a1073e7e430fbb0910e239ab3dbbc454993943ad586daf04a.jpg",
                                    "isPopup": false,
                                    "isBackground": false
                                }
                            ],
                            "posItemCode": null,
                            "isInStock": true,
                            "spaItemCode": null,
                            "sosItemCode": null,
                            "sortOrder": 1
                        }
                    ]
                },
                "succeeded": true
            }
        }
    ],
    "status": "Success"
}

For testing this scenario I have written below script in “Tests”:

pm.test('Status code is 200', function () {
  pm.response.to.have.status(200);
});

var jsonData = JSON.parse(responseBody)
var i

categoryItems = _.get(jsonData, 'responses[0].getSectionsCategoriesItems.content.categoryItems');

modifiers = _.get(jsonData, 'responses[0].getSectionsCategoriesItems.content.categoryItems[0].modifiers');

modifierOptions = _.get(jsonData, 'responses[0].getSectionsCategoriesItems.content.categoryItems[0].modifiers[0].modifierOptions');

var result;
for (i = 0; i < categoryItems.length; i++) {
  for (j = 0; j < modifiers.length; j++) {

    if ((modifiers[j] !== null) && (modifierOptions.length === null)) {
      var categoryItemName = _.get(categoryItems, `${i}.name`);
      var modifierName = _.get(modifiers, `${j}.name`);
      console.log(categoryItemName + " which has " + modifierName);
      result = true
    } else
      result = false;
  }
}

if (result === true)
  console.log("Test
    case Passed")
else
  console.log("Test
    case Failed")

I am getting “Test Failed” result on the console.

Appreciate your assistance ASAP.

Thanks in advance! :slight_smile:

@rajshrees Please fix the response body to be a valid JSON, it’s broken.
Will debug the script once it’s fixed and will help you out with the issue.

Thanks!

@singhsivcan are you able to copy the JSON response now?

@singhsivcan is it better now? Please let me know if you need any more information.

@rajshrees So inside your nested for loop you have this condition where you’re checking if the modifiers are not null and the length is also not null.

There are two things that I’d like to point out here that are wrong:

  1. If an item is not there in an array then it’ll return as undefined and not null in JavaScript.
    For eg:
let arr = [1, 2, 3];
console.log(arr[5]); // undefined
  1. If you’re checking the length of an array and you want to check if the array is empty with that, then also the length will not return as null, it’ll return as 0.
    For eg:
let arr = [];
console.log(arr.length); // 0 

So both the conditions in your if statement are wrong and will fail.

What you should be writing is this:

if (modifiers[j] && !modifierOptions.length) {
  // your code here
}

This makes sure that both the values are truthy i.e. modifiers[j] is not a falsy value and also the modifierOptions.length is more than 0, since 0 is a falsy value, doing the negate of that you’ll get 1 which is truthy and your condition will pass.

After making the above change here’s the result:
image

3 Likes

Thank you @singhsivcan :grinning:

above solution is not working for the below API endpoint.

getSectionsCategoriesItemsByGuest

Response of this get API endpoint is:

   {
    "sessionToken": "kDCp36W91ogKAAAABwAAAAAAAAAkYmEwNTRhNzctYWIyZC00ZTZkLWJmZTctMzQ0ZjYyMWQyZjFmAQAAAANBQ0cCAAAAA0FDUAYAAAACMTkFAAAAA2VuZwMAAAAHMTI5ODc3OAQAAAADMTAyAQAAAAAAAAA.-aCxKVIYYrd2t5euF6ZPPVlmPCOxkK97du9soX1e_KI",
    "responsesIncluded": "getSectionsCategoriesItemsByGuest",
    "responses": [
        {
            "getSectionsCategoriesItemsByGuest": {
                "content": {
                    "sections": [
                        {
                            "id": 733977,
                            "code": "51f0c8cb-93c7-4230-8291-4761a91fd374",
                            "referenceCode": null,
                            "name": "Dynamic Widget Section Visible to specific room",
                            "internalName": "Dynamic Widget Section Visible to specific room",
                            "gridFormat": "",
                            "headerTitle": "<p>Dynamic Widget Section Visible to specific room</p>\n",
                            "headerBody": "<p>Dynamic Widget Section Visible to specific room</p>\n",
                            "relatedItemsTitle": null,
                            "iconCode": "i-f-cart-1",
                            "type": "StandardContent",
                            "customAction": "",
                            "url": null,
                            "displayOrder": 10,
                            "infoModules": [],
                            "categories": [
                                {
                                    "subCategories": [],
                                    "imageUrl": null,
                                    "headerTitle": "<p>Lunch Category</p>\r\n",
                                    "headerBody": "<p>Lunch Category</p>\r\n",
                                    "type": "StandardContent",
                                    "displayOrder": 0,
                                    "externalUrl": null,
                                    "gridFormat": null,
                                    "fbDisplayType": null,
                                    "name": "Lunch Category",
                                    "relatedItemsTitle": null,
                                    "updateDate": "2019-04-04T10:04:51.39",
                                    "sectionCode": "51f0c8cb-93c7-4230-8291-4761a91fd374",
                                    "code": "230725f9-9b5c-45fd-937b-a5b08c2d1674",
                                    "useGallery": false,
                                    "categoryExtraCharges": [],
                                    "teasers": [],
                                    "analyticsTag": null
                                }
                            ],
                            "imageUrl": "https://irisv4neuqaasstore.blob.core.windows.net/fileresources/public/iris/ACG/maini-s-green-leaf8e97ca65a1b44e798b893da8fd19aa84.jpg",
                            "teasers": [],
                            "analyticsTag": null,
                            "hideFromWebValet": false,
                            "hideFromNativeApps": false,
                            "visibleToRooms": "102",
                            "isEncryptedUrl": false,
                            "isVisibleToAllRooms": false,
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "sectionOutlets": [],
                            "widgetReferenceCode": null
                        },
                        {
                            "id": 733985,
                            "code": "f03947c2-e47c-4da2-93d5-cb275214edb1",
                            "referenceCode": null,
                            "name": "Room Specific - Standard Section - Product Items with Modifiers",
                            "internalName": "Room Specific - Standard Section - Product Items with Modifiers",
                            "gridFormat": "",
                            "headerTitle": "<p>Room Specific - Standard Section - Product Items with Modifiers</p>\n",
                            "headerBody": "<p>Room Specific - Standard Section - Product Items with Modifiers</p>\n",
                            "relatedItemsTitle": null,
                            "iconCode": "i-f-pause-1",
                            "type": "StandardContent",
                            "customAction": "",
                            "url": null,
                            "displayOrder": 18,
                            "infoModules": [],
                            "categories": [
                                {
                                    "subCategories": [],
                                    "imageUrl": null,
                                    "headerTitle": "<p>Category - Product Items with Modifiers</p>\r\n",
                                    "headerBody": "<p>Category - Product Items with Modifiers</p>\r\n",
                                    "type": "StandardContent",
                                    "displayOrder": 0,
                                    "externalUrl": null,
                                    "gridFormat": null,
                                    "fbDisplayType": null,
                                    "name": "Category - Product Items with Modifiers",
                                    "relatedItemsTitle": null,
                                    "updateDate": "2019-04-04T10:04:51.44",
                                    "sectionCode": "f03947c2-e47c-4da2-93d5-cb275214edb1",
                                    "code": "58104a1b-d19c-41a2-a77d-6f2688bfd709",
                                    "useGallery": false,
                                    "categoryExtraCharges": [],
                                    "teasers": [],
                                    "analyticsTag": null
                                }
                            ],
                            "imageUrl": null,
                            "teasers": [],
                            "analyticsTag": null,
                            "hideFromWebValet": false,
                            "hideFromNativeApps": false,
                            "visibleToRooms": "102",
                            "isEncryptedUrl": false,
                            "isVisibleToAllRooms": false,
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "sectionOutlets": [],
                            "widgetReferenceCode": null
                        }
                    ],
                    "categoryItems": [
                        {
                            "code": "12fa0b39-6e65-496c-bba8-b96b93697dec",
                            "price": 10,
                            "imageUrl": null,
                            "directContentParameter": null,
                            "type": "Product",
                            "name": "Lunch Item",
                            "shortDescription": "<p>Lunch Item</p>\r\n",
                            "longDescription": "<p>Lunch Item</p>\r\n",
                            "categoryCode": "230725f9-9b5c-45fd-937b-a5b08c2d1674",
                            "itemCode": "007e69fc-9f60-405f-9740-deb8e60eee84",
                            "printEnabled": false,
                            "emailSharingEnable": false,
                            "qrCodeEnabled": false,
                            "promo": false,
                            "directContentType": null,
                            "availabilityPeriod": null,
                            "attributes": [],
                            "availabilityPeriods": [
                                {
                                    "name": "Lunch",
                                    "description": "Lunch",
                                    "code": "a80f4518-9c00-45bf-9335-bf8bdc0a7feb",
                                    "startTime": "12:00:00",
                                    "endTime": "15:00:00",
                                    "isMonday": true,
                                    "isTuesday": true,
                                    "isWednesday": true,
                                    "isThursday": true,
                                    "isFriday": false,
                                    "isSaturday": false,
                                    "isSunday": true
                                }
                            ],
                            "availabilitySummary": {
                                "monday": {
                                    "periods": [
                                        {
                                            "start": 720,
                                            "end": 900
                                        }
                                    ]
                                },
                                "tuesday": {
                                    "periods": [
                                        {
                                            "start": 720,
                                            "end": 900
                                        }
                                    ]
                                },
                                "wednesday": {
                                    "periods": [
                                        {
                                            "start": 720,
                                            "end": 900
                                        }
                                    ]
                                },
                                "thursday": {
                                    "periods": [
                                        {
                                            "start": 720,
                                            "end": 900
                                        }
                                    ]
                                },
                                "sunday": {
                                    "periods": [
                                        {
                                            "start": 720,
                                            "end": 900
                                        }
                                    ]
                                }
                            },
                            "relatedCategoryItemCodes": [],
                            "modifiers": [],
                            "analyticsTag": null,
                            "templateTag": null,
                            "buttons": [],
                            "itemImages": [],
                            "posItemCode": null,
                            "isInStock": true,
                            "spaItemCode": null,
                            "sosItemCode": null,
                            "sortOrder": 1
                        },
                        {
                            "code": "b9310f4c-5e33-4460-8d82-0acce29fac2a",
                            "price": 20,
                            "imageUrl": null,
                            "directContentParameter": null,
                            "type": "Product",
                            "name": "Product Item with Item Modifiers",
                            "shortDescription": null,
                            "longDescription": null,
                            "categoryCode": "58104a1b-d19c-41a2-a77d-6f2688bfd709",
                            "itemCode": "2e2da95e-ecb3-4b2e-b659-6c4ed9209c20",
                            "printEnabled": false,
                            "emailSharingEnable": false,
                            "qrCodeEnabled": false,
                            "promo": false,
                            "directContentType": null,
                            "availabilityPeriod": null,
                            "attributes": [],
                            "availabilityPeriods": [],
                            "availabilitySummary": {},
                            "relatedCategoryItemCodes": [],
                            "modifiers": [
                                {
                                    "name": "Visible Multi Select Item Modifier with Invisible Options",
                                    "code": "1b1211ab-d6b1-489f-a3ff-5cf417f82d52",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": false,
                                    "sortOrder": 2,
                                    "maximumQuantity": null,
                                    "modifierOptions": []
                                },
                                {
                                    "name": "Multi Select Item Modifier",
                                    "code": "753dc005-13ac-4831-a228-7c4b542eab84",
                                    "posItemCode": null,
                                    "parentModifierOptionCode": null,
                                    "type": "multiselect",
                                    "isRequired": false,
                                    "sortOrder": 3,
                                    "maximumQuantity": null,
                                    "modifierOptions": [
                                        {
                                            "value": "Option 1",
                                            "code": "dd4bb4e8-ecd4-4504-85a7-bef127d91369",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 1",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        },
                                        {
                                            "value": "Option 2",
                                            "code": "b821b52d-e453-464b-bfc2-5146ff092321",
                                            "price": 0,
                                            "modifierOptionCode": "753dc005-13ac-4831-a228-7c4b542eab84",
                                            "subModifiers": [],
                                            "timeValue": 0,
                                            "name": "Option 2",
                                            "posItemCode": null,
                                            "optionType": "Text"
                                        }
                                    ]
                                }
                            ],
                            "analyticsTag": null,
                            "templateTag": null,
                            "buttons": [],
                            "itemImages": [],
                            "posItemCode": null,
                            "isInStock": true,
                            "spaItemCode": null,
                            "sosItemCode": null,
                            "sortOrder": 1
                        }
                    ]
                },
                "succeeded": true
            }
        }
    ],
    "status": "Success"
}

I have written below script in Tests

var jsonData = JSON.parse(responseBody);
var i;

categoryItems = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems');

//console.log(categoryItems.length);

modifiers = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers');

modifierOptions = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers[0].modifierOptions');

var result;
for (i=0; i<categoryItems.length; i++)
{
    for (j=0; j<modifiers.length; j++)
    {
        if (modifiers[j] !== 0)
        {
            var size = modifiers[j].modifierOptions.length;
                        
            if(size === 0)
            {
                var categoryItemName = _.get(categoryItems, `${i}.name`);
                var modifierName = _.get(modifiers, `${j}.name`);
                console.log(categoryItemName +" which has " +modifierName);
                result = true;
            }
        }
        else
            result = false;
    }
}


if (result === true)
    console.log("Test case Passed");
else
    console.log("Test case Failed");

Output in console is:

Lunch Item which has Visible Multi Select Item Modifier with Invisible Options
Product Item with Item Modifiers which has Visible Multi Select Item Modifier with Invisible Options
Test case Passed

I just want the below result in console:

Product Item with Item Modifiers which has Visible Multi Select Item Modifier with Invisible Options
Test case Passed

Also I want to extract the arrays in for loop instead of writing it as hard coded like below:

categoryItems = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems');

modifiers = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers');

modifierOptions = _.get(jsonData, 'responses[0].getSectionsCategoriesItemsByGuest.content.categoryItems[1].modifiers[0].modifierOptions');

Could you please help me out on this?