# Sorting a string array numerically - How do I do it?

**URL:** <https://forum.kirupa.com/t/sorting-a-string-array-numerically-how-do-i-do-it/258665>\
**Category:** flash\
**Created:** [April 26, 2008, 2:29pm UTC](https://forum.kirupa.com/t/sorting-a-string-array-numerically-how-do-i-do-it/258665 "2008-04-26T14:29:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nawtwrong](https://avatars.discourse-cdn.com/v4/letter/n/4bbf92/32.png) [@nawtwrong](https://forum.kirupa.com/u/nawtwrong)\
**Post date:** [April 26, 2008, 2:29pm UTC](https://forum.kirupa.com/t/sorting-a-string-array-numerically-how-do-i-do-it/258665/1 "2008-04-26T14:29:11Z")

</div>

Hi,

Supposing I have an array with the following in:

```auto
 
myArray = ['left_1', 'left_3', '_left_5', '_left_12', 'left_10', 'left_2', 'left_6', 'left_9'];

```

If I want to sort that array numerically and I use myArray.sort(); or myArray.sort(Array.NUMERIC); left\_10 always comes before left\_1.

Because each item in my array has numbers and letters I think this is causing the problem. So my question is: does anyone know of a way of doing this?

Would I need a custom function and call it like this?

```auto
myArray.sort(customFunction);

```

Basically I want to sort the array so that the 1\_left comes before 10\_left and so on…

Any help is appreciated.

Thanks!!
