简体   繁体   中英

javascript appending to a variable from an array

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.

var mystring=array.join(", "); maybe?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM