Reorder numbers in string

Reorder numbers in string

I have a string with numbers:

10 9 8 11

I need to reorder them so they are in order like this:

8 9 10 11

So I'm using this function:

  1. strToAppend = strToAppend.split(' ');
  2.                 strToAppend.sort(function (a, b) {
  3.                     if (isNaN(a) || isNaN(b)) {
  4.                         return a > b ? 1 : -1;
  5.                     }
  6.                     return a - b;
  7.                 });

That works but the problem is that the string comes out like this:

891011

How can I reorder and still keep the spaces between the numbers?

8 9 10 11

I thought that "strToAppend" would be an array. If that would be the case I could loop through the numbers and add space, but when I'm trying to access one number using strToAppend[0] I get nothing.