Sorting Javascript array with strings and numbers -


I have a list of elements in JavaScript, as follows:

  myArray = ["Datastore a free space 34.23GB", "Datastore two free space 56.23 GB", ...]   

and so on. I would like to sort the array on freepace, so in the example above the datastore, the first element in the two array will be. The array is always created with "free space xx.xxGB", but in some cases the spaces can be 5 digits, so for example xxx.xxGB.

Can anyone provide a sort of sorting array please? I think I use something like

  "* - free space \ [1-9] [0-9] * GB"   

It should be

  myArray.sort ("* - spaces \ s [1-9] [0-9] * GB")?   

Is this correct or how do I do it? Many thanks in advance.

Drag and drop numeric parts in a custom sort function:

  myArray = [" Datastore a free space 34.23GB "," Datastore two free space 56.23GB "," Datastore three free space 6.23GB "]; var re = / ([0-9 .. ++) GB /; // get regex GR values ​​to get myArray = myArray.sort (function (a, b) {var ma = a.match (re); // Take GB values ​​from each stroke var mb = b.match (re ); / / The result is an array, in which the number on the position [1] (ma [1] - MB [1]);}; warning (myArray.join ("\ r \ n"));  < / pre>    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -