How to split a string and remove empty elements in JavaScript

1 Answer

0 votes
const str = " JavaScript    Python C";

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

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

*/

   
  

 



answered May 1, 2022 by avibootz
...