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
...