Jquery - parse a comma delimited string

carsRST
carsRST used Ask the Experts™
on
Is there a way in jquery to parse a comma delimited string?

It will always only be one line of data to parse.  


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
You may use $.map
http://api.jquery.com/jQuery.map/

$.map(youString.split(","), function(el, i) {

   alert("item number " + i + " is : "+ el ); 

});

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:

Author

Commented:
Thanks again!
Michel PlungjanIT Expert
Top Expert 2009

Commented:
A few comments

1) jQuery is not needed to (and afaik cannot) PARSE a comma delimited string - plain JS split(",") is the thing that does this and jQuery can then act on the resulting array..
2) jQuery map has a simpler sibling called each if you need to do something to each value.

So depending on what you need to do with the values, you may want to look into split, each and map in ascending order of complexity

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial