How to split a string into an array by delimiter and remove empty elements in JavaScript

1 Answer

0 votes
const s = "C#,JavaScript,,C,,,Python,,,,,C++,,";
  
const arr = s.split(",").filter(element => element !== "");

arr.forEach(element => console.log(element));



/*
run:

C#
JavaScript
C
Python
C++

*/

 



answered Sep 23, 2024 by avibootz
edited Sep 23, 2024 by avibootz
...