Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split string and push in array using jquery [duplicate]

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.

like image 235
user3124690 Avatar asked Mar 28 '14 09:03

user3124690


2 Answers

Use the String.split()

var array = string.split(',');
like image 86
Arun P Johny Avatar answered Oct 13 '22 17:10

Arun P Johny


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

array = array.concat(strx);
// ["a","b","c","d"]
like image 37
Iqbal Fauzi Avatar answered Oct 13 '22 17:10

Iqbal Fauzi