# Comparing array values

**URL:** <https://community.postman.com/t/comparing-array-values/75217>\
**Category:** Help Hub\
**Tags:** tests, variables, array, nested-array\
**Created:** [February 10, 2025, 6:00pm UTC](https://community.postman.com/t/comparing-array-values/75217 "2025-02-10T18:00:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruma204](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@ruma204](https://community.postman.com/u/ruma204)\
**Post date:** [February 10, 2025, 6:00pm UTC](https://community.postman.com/t/comparing-array-values/75217/1 "2025-02-10T18:00:16Z")

</div>

I am verifying if my values match with JSON response. Here is my code -

```auto
pm.test("Status test", function () {
    pm.response.to.have.status(200);
});

pm.test("Testing Related Products", function () {    
    let responseJSON = pm.response.json();
    
    if (responseJSON.contains.length > 0) {
        let expectedStrings = pm.variables.get("related_prod_ids").split(",");
        console.log("Expected String -",expectedStrings); //["111537", "111345"]
        let actualString = responseJSON.contains[0].relatedProducts.map(product => product.productCode.toString());
        console.log("Actual String -", actualString);//["111537"]
                
        if (pm.expect(actualString).to.have.members(expectedStrings)) {
            console.log("Testcase Passed!");
        } else {
            console.log("One or more Related Products did not match...!");
        }
    } else {
        console.log("Empty response...");
    }
});

```

Query - I get an error - _Testing Related Products | AssertionError: expected [‘111537’] to have the same members as [‘111537’, ‘111345’]_  
But Console never shows - _console.log(“One or more Related Products did not match…!”);_  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [February 10, 2025, 6:50pm UTC](https://community.postman.com/t/comparing-array-values/75217/2 "2025-02-10T18:50:56Z")

</div>

Hey @ruma204 👋🏼

Your second `if` statement contains an assertion function and not a conditional evaluation so it wouldn’t work in that statement.

That assertion should be inside the test function and will give you a yes/no answer against what you’re checking. I don’t see the need to have a nested if / else that writes a console log for that.
