Reputation: 3610
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. BIMO
or 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
Reputation: 16223
Try something like;
yourString = yourString.split('').sort().join('');
Upvotes: 2
Reputation: 145398
This is the shortest (maybe not the fastest though) way:
"MIBO".split("").sort().join(""); // "BIMO"
Upvotes: 7