JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = 'esgewg,wegewg,wegewgewg,wegwegweg,wegweg';
alert((str.match(/,/g)||[]).length);

var str = 'fegewhwehwehwehweh';
alert((str.match(/,/g)||[]).length);