Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript how to ascertain if it is a comma delimited list?

Tags:

javascript

I'm curious, how would you test a string and say "yep, that is a comma delimited list!" I'm not so worried about the 'comma delimited' part more that this string has more than one item in it?

Thanks, R.

like image 303
flavour404 Avatar asked Oct 27 '25 11:10

flavour404


2 Answers

How about:

stringObject.indexOf(",") >= 0
like image 128
George Phillips Avatar answered Oct 29 '25 05:10

George Phillips


To check if the string has more than one item, try something like:

str.split(",").length > 1

... although, as suggested in a comment, correct parsing is likely to be bit more complicated than this for the general case.

Edit:

whoops, misread language as Java - sorry.

like image 39
harto Avatar answered Oct 29 '25 07:10

harto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!