# Write a test to check values in the response are in ascending order

**URL:** <https://community.postman.com/t/write-a-test-to-check-values-in-the-response-are-in-ascending-order/12311>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json\
**Created:** [April 30, 2020, 6:49pm UTC](https://community.postman.com/t/write-a-test-to-check-values-in-the-response-are-in-ascending-order/12311 "2020-04-30T18:49:10Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![SabriH](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@SabriH](https://community.postman.com/u/SabriH)\
**Post date:** [April 30, 2020, 7:20pm UTC](https://community.postman.com/t/write-a-test-to-check-values-in-the-response-are-in-ascending-order/12311/2 "2020-04-30T19:20:34Z")

</div>

Hi @ksingh778,

I believe this has already been addressed here:

> [@Possibility to test if my id is sorted in ascending order in my body](https://community.postman.com/t/possibility-to-test-if-my-id-is-sorted-in-ascending-order-in-my-body/9791/2):
>
> Using pure JavaScript and broken down in smaller pieces pm.test("All ids are ascending", () =\> { const response = pm.response.json(); // Extract all ids in an array const ids = response.data.map(item =\> item.id); // Check that all are ascending function isAscending(a) { return a.every((x, i) =\> { return i === 0 || x \>= a[i-1]; }); } pm.expect(isAscending(ids)).to.be.true; }); Simplified version pm.test("All ids are ascending",…

Or at least can help accomplish your requirements.

Hope this helps!

---

_[View the full topic](https://community.postman.com/t/write-a-test-to-check-values-in-the-response-are-in-ascending-order/12311)._
