[Edit]
+
0
-
0

js split string into array by comma and space

1 2 3 4 5 6 7 8 9 10 11 12 13
function splitString(string) { return string.split(/[ ,]+/); } // Usage example: const text1 = 'Split,this text'; const text2 = 'Another, , ,example,,,,text to , , , split'; console.log( splitString(text1) ); // ['Split', 'this', 'text'] console.log( splitString(text2) ); // ['Another', 'example', 'text', 'to', 'split']