12
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.

2
  • Why would you use jQuery for this? Commented Mar 28, 2014 at 9:36
  • 3
    Use String.split() Commented Mar 28, 2014 at 9:37

4 Answers 4

50

Use the String.split()

var array = string.split(',');
Sign up to request clarification or add additional context in comments.

Comments

6
var string = 'a,b,c,d',
    strx   = string.split(',');
    array  = [];

array = array.concat(strx);
// ["a","b","c","d"]

Comments

2

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

Comments

0
var string = string.split(",");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.