# Verify dynamic array is sorting correctly

**URL:** <https://community.postman.com/t/verify-dynamic-array-is-sorting-correctly/34217>\
**Category:** Help Hub\
**Created:** [April 4, 2022, 6:44pm UTC](https://community.postman.com/t/verify-dynamic-array-is-sorting-correctly/34217 "2022-04-04T18:44:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylan-neal](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dylan-neal](https://community.postman.com/u/dylan-neal)\
**Post date:** [April 4, 2022, 6:44pm UTC](https://community.postman.com/t/verify-dynamic-array-is-sorting-correctly/34217/1 "2022-04-04T18:44:12Z")

</div>

Hello! I want to verify that the data being returned in an array is in ascending order (by first\_name). This data will often be new or different, so the test will need to be able to read the response dynamically if that makes sense.

```auto
[
    {
        "id": 15640,
        "email": "123abc@gmail.com",
        "first_name": "123",
        "lastname": "123",
        "events_purchased": 1,
        "queue_events_entries": 0,
        "tickets_purchased": 1,
        "events_followed": 0,
        "overall_spend": 10.90,
        "last_purchase": 1648855932000
    },
    {
        "id": 15020,
        "email": "darrel.neal@gmail.com",
        "age": 28,
        "first_name": "darrel",
        "lastname": "neal",
        "events_purchased": 1,
        "queue_events_entries": 0,
        "tickets_purchased": 3,
        "events_followed": 0,
        "overall_spend": 52.70,
        "last_purchase": 1648763935000,
        "birth_date": "1994-03-02"
    },
    {
        "id": 15639,
        "email": "zelda666@gmail.com",
        "first_name": "Zelda",
        "lastname": "Zelda",
        "events_purchased": 1,
        "queue_events_entries": 0,
        "tickets_purchased": 1,
        "events_followed": 0,
        "overall_spend": 10.90,
        "last_purchase": 1648855790000
    }
]

```

I tried this test to verify the sorting works, however when I change the sorting parameter in the url to sort by tickets instead of name, it fails:

```auto
pm.test("sorting", function () {
    //loop array to get all first names
    let name = response.map(tool => tool.first_name);

        //sort first names and ignore case sensitivity
        let names = name.sort((a, b) => a.localeCompare(b, undefined, {sensitivity: 'base'}))
        console.log(names)

    pm.expect(response.first_name)===(names)
});

```
