How to sort an array of strings in ascending order with Node.js

1 Answer

0 votes
const arr = ["php", "typescript", "c++", "c", "nodejs", "javascript", "python"]; 
   
arr.sort((a, b) => (a > b ? 1 : -1));
    
console.log(arr);
   
    
  
    
/*
run:
    
[ 'c', 'c++', 'javascript', 'nodejs', 'php', 'python', 'typescript' ]
    
*/

 



answered Nov 11, 2021 by avibootz
edited Feb 26, 2022 by avibootz

Related questions

2 answers 150 views
1 answer 160 views
...