i am not sure if its a total n00b question but here goes.
i have a JSON array with values:
array[0].1 = "the value I want"
now I want to include all "the value I want" into this one variable like:
the value I want [1], the value I want [2]....
how do i do it? infact if there is a way I can get the comma seperated values into a variable as it is please let me know.
EDIT: CLARIFICATION OF QUESTION
I want to create a variable in which i want to append all the data from the JSON array i have. for example, if the JSON data reads:
data[0] = value, data[1] = value, data[2] = value, ...
i want all the "value" appended into a variable.
2 Answers 2
var mystring=array.join(", "); maybe?
Comments
var b = 'I,am,a,JavaScript,hacker'
var temp = new Array();
temp = b.split(',');
Now the string has been split into 5 strings that are placed in the array temp. The commas themselves are gone.
temp[0] = 'I';
temp[1] = 'am';
temp[2] = 'a';
temp[3] = 'JavaScript';
temp[4] = 'hacker.';
Taken from QuirksMode.
join is the "opposite" of split - use it to append the elements of an array together into a variable.
var j = temp.join(','); // sets j to 'I,am,a,JavaScript,hacker'
array[0].1is invalid syntax..and identifiers cannot start with a number. the correct syntax would bearray[0][1]