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 194 views
2 answers 189 views
1 answer 145 views
1 answer 154 views
1 answer 158 views
1 answer 148 views
...