Sort string in Javascript

Something Like that:
sort()

add this JS code.

JS

var oldStr = "tima";
var newArr = oldStr.split('');
var newStr = newArr.sort();
var JoinStr = newStr.join('');

console.log(oldStr);
console.log(newArr);
console.log(newStr);
console.log(JoinStr);

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”NwVerW” default_tab=”js,result” user=”pradeepanvi”]See the Pen Sort string in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

You can check console.

Sort string function in javascript

add this JS code.

JS

function sortStr(txt){
  return txt.split('').sort().join('');
}

console.log(sortStr('timedbaz'))

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”wPbRow” default_tab=”js,result” user=”pradeepanvi”]See the Pen Sort string function in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

You can check console.

Leave a Reply

Your email address will not be published. Required fields are marked *