How to split a string into an array by delimiter and remove empty elements in TypeScript

1 Answer

0 votes
const s: string = "C#,TypeScript,,C,,,Python,,,,,C++,,";
  
const arr: string[] = s.split(",").filter(element => element !== "");

arr.forEach(element => console.log(element));



/*
run:

"C#" 
"TypeScript" 
"C" 
"Python" 
"C++" 

*/

 



answered Sep 23, 2024 by avibootz
...