# Incorrect sorting of string with spaces, numbers, and special characters using Sort By/Order By of Loadash

**URL:** <https://community.postman.com/t/incorrect-sorting-of-string-with-spaces-numbers-and-special-characters-using-sort-by-order-by-of-loadash/48481>\
**Category:** Help Hub\
**Tags:** tests, sort\
**Created:** [June 13, 2023, 3:57pm UTC](https://community.postman.com/t/incorrect-sorting-of-string-with-spaces-numbers-and-special-characters-using-sort-by-order-by-of-loadash/48481 "2023-06-13T15:57:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![krtorres](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@krtorres](https://community.postman.com/u/krtorres)\
**Post date:** [June 13, 2023, 3:57pm UTC](https://community.postman.com/t/incorrect-sorting-of-string-with-spaces-numbers-and-special-characters-using-sort-by-order-by-of-loadash/48481/1 "2023-06-13T15:57:06Z")

</div>

I have this code where a response array will be sorted out by name.

```
 var responseArray = pm.response.json();    
 var _ = require('lodash');

 let expSortedOrder = _.sortBy(responseArray.results, (results) => {return _.lowerCase(results.name)});

 console.log(expSortedOrder);
 pm.expect(responseArray.results).to.eql(expSortedOrder);

```

I am having issue with the way this sorts the name values with space and numbers. API response sorted the name with space first then number:

```
[
   {
       "id": 123,
       "name": "test name"
   },
   {
       "id": 456,
       "name": "test.name"
   },
   {
       "id": 789,
       "name": "Test1 Name"
   }

```

]

Test script using loadash sorted the name with space first then number:

```
[
   {
       "id": 789,
       "name": "Test1 Name"
   },
   {
       "id": 123,
       "name": "test name"
   },
   {
       "id": 456,
       "name": "test.name"
   }

```

]

Is there a way for me to change what the sort should prioritize?

---

<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:** [April 29, 2025, 10:25am UTC](https://community.postman.com/t/incorrect-sorting-of-string-with-spaces-numbers-and-special-characters-using-sort-by-order-by-of-loadash/48481/2 "2025-04-29T10:25:17Z")

</div>

Closed on April 29, 2025, 10:25am UTC


