Sorting string in javascript ES6

1 year ago23k times

Sorting string in Javascript ES6. By default javascript, the sort method organizes elements alphabetically(i.e A-Z).

const items = ['arms','red','green','orange','yellow'];
//sort items 
const sortitems = items.sort(); 
console.log(sortitems); // ['arms', 'green', 'orange', 'red', 'yellow']

//reverse the items 

const reverseitems = sortitems.reverse();
console.log(reverseitems); // ['yellow', 'red', 'orange', 'green', 'arms']

Add Answer

Add a codeAdd Code
Remove adsremove

Latest codes

view all

Latest Snippets

view all