# Test to find a keyword in a response array

**URL:** <https://community.postman.com/t/test-to-find-a-keyword-in-a-response-array/29130>\
**Category:** Help Hub\
**Created:** [October 27, 2021, 6:54am UTC](https://community.postman.com/t/test-to-find-a-keyword-in-a-response-array/29130 "2021-10-27T06:54:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![freakend](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/freakend/32/10153_2.png) [@freakend](https://community.postman.com/u/freakend)\
**Post date:** [October 27, 2021, 6:54am UTC](https://community.postman.com/t/test-to-find-a-keyword-in-a-response-array/29130/1 "2021-10-27T06:54:57Z")

</div>

Hi, good day everyone, i am new here,

_My question_:  
I have a response data looking like this

```auto
[
    {
        "Outlet": "Outlet1",
        "Inventory": 12
    },
    {
        "Outlet": "Outlet2",
        "Inventory": 0
    },
    {
        "Outlet": "Outlet3",
        "Inventory": 3
    },
    {
        "Outlet": "Outlet4",
        "Inventory": 0
    }
}

```

_How I found the problem_:

I need to verify if the outlet 1 inventory is exact 12, and every other data EXCEPT outlet1 inventory is 0. do i need to loop the test?

_I’ve already tried_:

```auto
pm.test("Inventory.OnHand Outlet1 == 6", () => {
    let Outlet1Result = jsonData.find(a => a.Outlet === "Outlet1")
    pm.expect(Outlet1Result.Outlet).to.eql("Outlet1")
    pm.expect(Outlet1Result.Inventory).to.eql(12)
});

pm.test("Inventory.OnHand not Outlet1 == 0", () => {
    if (jsonData.Outlet !== "Outlet1") {
    jsonData.forEach(function() {
        let result2 = jsonData.find(a => a.Outlet !== "Outlet1")
        pm.expect(result2.Inventory).to.eql(0)
    }) ;
  }  
});

```

I have tried using this 2 test, the first test worked just fine, but i think the second test is wrong because it’s passed, it should not be passed since outlet 3 inventory is 3, the text expect it to be 0

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [October 27, 2021, 3:25pm UTC](https://community.postman.com/t/test-to-find-a-keyword-in-a-response-array/29130/2 "2021-10-27T15:25:35Z")

</div>

Hey @freakend ! Welcome to the community 🥳

You can save the response and loop through the objects to find and perform the tests you need, Have a look at how this can simplified.

```auto
var jsonData=pm.response.json();

pm.test('Inventoy Check', () => {
    _.each(jsonData, (item) => {
       
        if(item.Outlet=="Outlet1")
        pm.expect(item.Inventory).to.eql(12)
        
        else
        pm.expect(item.Inventory).to.eql(0)
    })
})

```

Good luck!
