How to sort an array of strings in ascending order with TypeScript

1 Answer

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

 



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