Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

var string = 'a,b,c,d';
var array = [];

As we can see above I have one string values with separator*(,)*. I want to split these values and wants to push in the array. At last I want to read my array by using for loop. Please suggest.

share|improve this question

marked as duplicate by RGraham, fancyPants, VMAtm, manuell, Tim B Mar 28 '14 at 10:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Why would you use jQuery for this? –  fzzle Mar 28 '14 at 9:36
1  
Use String.split() –  Arun P Johny Mar 28 '14 at 9:37

4 Answers 4

up vote 1 down vote accepted

Use the String.split()

var array = string.split(',');
share|improve this answer

You don't need jQuery for that, you can do it with normal javascript:

http://www.w3schools.com/jsref/jsref_split.asp

var str = "a,b,c,d";
var res = str.split(","); // this returns an array
share|improve this answer
var string = string.split(",");
share|improve this answer
var string = 'a,b,c,d',
    strx   = string.split(',');
    array  = [];

array = array.concat(strx);
// ["a","b","c","d"]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.