Advertisement
elena1234

Sort in Ascending Order - JavaScript

Aug 19th, 2021
2,785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.     array.sort((a, b) => a.localeCompare(b)) // sort in Ascending order
  3.         .forEach((element, index) => {
  4.             console.log(index + 1 + '.' + element)
  5.         });
  6. }
  7.  
  8. solve(["John", "Bob", "Christina", "Ema"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement