EDIT:

The problem is I need to specify the array indexes dynamically. I cannot put '1', or '2', it will be within a loop:

var current = ....

array[current] = ....

I have this:

array[1] = new Array('A','B','C');  
array[2] = new Array('B','A','C');

However, I need to send this to the server using ajax (I'm using jQuery), and the array doesn't seem to be in any state to send.

reason I need to use these indexes 1,2 etc is because I need to be able to overwrite a previous array with a new order if need be. To change the above index 1 I'd do:

array[1] = new Array('C','B','A');

JSON.stringify is returning blank:

{"1":[]}
share|improve this question

2  
Sorry; I have no idea what you're talking about! – Lightness Races in Orbit Sep 11 '11 at 14:21
1  
I cannot imagine what the problem could be. Defining arrays should not be a problem. You could also do array = [, array, array2]; or array = {1: array, 2: array2};, depending on which results you want. – Felix Kling Sep 11 '11 at 14:22
4  
So if nobody understands your question and nobody bothers telling you that they don't understand your question... you won't know to clarify your question and you won't get any answers. – BoltClock Sep 11 '11 at 14:23
2  
@Zenph: The comment is intended to persuade you to clarify your question into something that I (and others) can understand! – Lightness Races in Orbit Sep 11 '11 at 14:23
1  
@Zenph: I was ready from the get go, which was 12 minutes ago; I asked you to ask an actual question and you've yet to manage to do so. Either provide a testcase on jsfiddle.net or give up. – Lightness Races in Orbit Sep 11 '11 at 14:34
show 7 more comments
feedback

closed as not a real question by Lightness Races in Orbit, Felix Kling, Armen Tsirunyan, Juhana, Graviton Sep 12 '11 at 4:59

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

up vote 0 down vote accepted

You can use an array of arrays. The JSON for that would be:

[["A","B","C"],["B","A","C"]]

The index for the array is however zero based. If you need to start at 1, you need an object instead:

{"1":["A","B","C"],"2":["B","A","C"]}
share|improve this answer
Misleading to write unencapsulated JSON on a question about Javascript. – Lightness Races in Orbit Sep 11 '11 at 14:29
So down vote like you did mine! – mplungjan Sep 11 '11 at 15:23
@mplungjan: The difference is that this actually is JSON. – Guffa Sep 11 '11 at 15:44
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.