# .sort() Method Not Sorting Numbers Array

**URL:** <https://forum.codewithmosh.com/t/sort-method-not-sorting-numbers-array/18563>\
**Category:** JavaScript\
**Created:** [March 6, 2023, 2:28pm UTC](https://forum.codewithmosh.com/t/sort-method-not-sorting-numbers-array/18563 "2023-03-06T14:28:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sterlz08](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sterlz08](https://forum.codewithmosh.com/u/sterlz08)\
**Post date:** [March 6, 2023, 2:28pm UTC](https://forum.codewithmosh.com/t/sort-method-not-sorting-numbers-array/18563/1 "2023-03-06T14:28:01Z")

</div>

Can someone tell me why my array is not being sorted numerically? I could understand if the elements were being sorted alphabetically but they’re showing as all number types.

 ![Screenshot 2023-03-06 at 9.24.42 AM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/f/ff09b34aec8184198722301e73583ebac5ec495d.png)

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [March 11, 2023, 9:11am UTC](https://forum.codewithmosh.com/t/sort-method-not-sorting-numbers-array/18563/2 "2023-03-11T09:11:24Z")

</div>

If you don’t provide a compare function the elements are sorted as strings. The conversion to string is just done for comparison - it does not change the type of the elements.

> **[Array.prototype.sort() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)**
>
> The sort() method sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code...
