How to sort an array of strings ignoring the case in TypeScript

1 Answer

0 votes
let arr = ["php", "typescript", "c++", "c", "TYPESCRIPT", "C++", "nodejs", "C", "JAVASCRIPT"]; 

arr.sort((a, b) => {
  return a.localeCompare(b, undefined, {sensitivity: 'base'});
});

   
console.log(arr);
  
   
   
   
/*
run:
   
["c", "C", "c++", "C++", "JAVASCRIPT", "nodejs", "php", "typescript", "TYPESCRIPT"] 
   
*/
  

 



answered Feb 26, 2022 by avibootz
...