0

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.

4
  • 4
    array[0].1 is invalid syntax. Commented Jan 12, 2010 at 19:15
  • why is it invalid. i specifically mentioned its JSON data. Commented Jan 12, 2010 at 19:23
  • Because only an identifier can follow the . and identifiers cannot start with a number. the correct syntax would be array[0][1] Commented Jan 12, 2010 at 19:29
  • Your question still doesn't make sense. Post the data and the exact output you want if you can't figure out a better way to phrase it. Commented Jan 12, 2010 at 19:43

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1
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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.