4

I want to store comma separate values into array. Later i want check it with different check.

var_str= name,address,state,city // I want make array from this variable 

How could i do this...

Thanks..

Joko Wandiro
  • 1,957
  • 1
  • 18
  • 28

3 Answers3

6

(Assuming that you have a string and want to convert it to an array)Split method on strings splits strings on a separator.

var str = "name,address,state,city";
var arr = str.split(',');
dheerosaur
  • 14,736
  • 6
  • 30
  • 31
1

if you have such string:

var _str= 'name,address,state,city';

to get array from string use split javascript function:

var arr = _str.split(",");
Andrew Orsich
  • 52,935
  • 16
  • 139
  • 134
0

If they're strings, jut give it array notation:

var str = [name,address,state,city];

in this array str[0] would be name, etc. If they're not string's variables...I'm unsure what you're asking.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155