How to split a string and remove empty elements in Node.js

1 Answer

0 votes
const str = " NodeJS    Python C PHP";

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

console.log(arr);
 
 
 
 
 
/*
run:
 
[ 'NodeJS', 'Python', 'C', 'PHP' ]

*/

   
  

 



answered May 1, 2022 by avibootz

Related questions

2 answers 217 views
2 answers 206 views
1 answer 164 views
1 answer 170 views
1 answer 173 views
1 answer 169 views
...