How to split a string and remove empty elements in TypeScript

1 Answer

0 votes
const str = " JavaScript    Python C C++";

const arr = str.split(' ').filter(element => element);

console.log(arr);
 
 
 
 
/*
run:
 
["JavaScript", "Python", "C", "C++"] 

*/

 



answered May 1, 2022 by avibootz
...