Somnath Kharat
Somnath Kharat

Reputation: 3610

Sort a single string in ascending and alphapetical order

My Scenerio:

I have a hidden field with the id; hndSelectedSurface. I extract the value of the Field into a string(single word). e.g.MIBO or DCAB. A need it to be sorted in alphabetical order i.e. BIMOor ABCD

I tried the sort Method But can't get it to work the way i want. I need it to work in jquery or javascript

Upvotes: 1

Views: 1438

Answers (2)

DarkAjax
DarkAjax

Reputation: 16223

Try something like;

yourString = yourString.split('').sort().join('');

JSFiddle Demo

Upvotes: 2

VisioN
VisioN

Reputation: 145398

This is the shortest (maybe not the fastest though) way:

"MIBO".split("").sort().join("");  // "BIMO"

Upvotes: 7

Related Questions