javascript - Sort array of strings by portion of each string -



javascript - Sort array of strings by portion of each string -

i need sort array of strings portion of each string.

here list:

[ "5,758,zumba,13:00:00", "3,541,vinyasa level 2/3,10:30:00", "3,559,mat pilates,18:30:00" ]

how can sort sec value? order need is

541, 559, 758

you can utilize custom sort function:

class="snippet-code-js lang-js prettyprint-override">var array = ["5,758,zumba,13:00:00","3,541,vinyasa level 2/3,10:30:00","3,559,mat pilates,18:30:00"]; array.sort(function(a, b) { var c = a.split(',')[1]; var d = b.split(',')[1]; if (c < d) { homecoming -1; } if (c > d) { homecoming 1; } homecoming 0; }); console.log(array);

javascript arrays sorting

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -