How to match ids in an array response

I have a response in which I need to match the id to have 15 in it. So if the id is 30015 it should pass and it should check for each id in the array.

[

    {

        "id": 30015,

        "activationCode": 999999915,

        "duration": -99,

        "dob": 0,

        "alias": 0,

        "reannotationStatus": null,

        "activationDate": 1581346651000,

        "status": "Archived",

        "mobile": 0,

        "wearable": 0

    },

    {

        "id": 1015,

        "activationCode": 111000015,

        "duration": -99,

        "reannotationStatus": null,

        "activationDate": 1594674288000,

        "status": "Archived",

        "mobile": 1597095628,

        "wearable": 0

    },

    {

        "id": 1115,

        "activationCode": 111000115,

        "duration": 3600000,

        "reannotationStatus": null,

        "activationDate": 1597091723000,

        "status": "Active",

        "mobile": 1597095638,

        "wearable": 0

    },

    {

        "id": 1151,

        "activationCode": 111000151,

        "duration": 3600000,

        "reannotationStatus": null,

        "activationDate": 1597091724000,

        "status": "Active",

        "mobile": 1597095643,

        "wearable": 0

    },

    {

        "id": 1158,

        "activationCode": 111000158,

        "duration": 3600000,

        "reannotationStatus": null,

        "activationDate": 1597091724000,

        "status": "Active",

        "mobile": 1597095643,

        "wearable": 0

    }
]

Hey @rajeshnm8

Welcome to the community! :trophy:

Can 15 appear in any part of value? At the start? At the end?

Hello @danny-dainton

Great to see you here. I have been using your htmlextra report and its beautiful. Thank you for putting it together.

Regarding your question, Yes 15 can appear anywhere in an id.

This is quite hacky but might work for what you need:

pm.test("Id includes the number 15", () => {
    _.each(pm.response.json(), (item) => {
        pm.expect(item.id, `${item.id} - does not include 15.`).to.match(/15/g)
    })
})

Someone might have a better and more robust solution though. :smiley:

That worked like a charm. Thank you for your help and time.