-3

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":[]}
Damien Roche
  • 13,189
  • 18
  • 68
  • 96
  • 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
  • Just clarified. I imagine it is something to do with 'stringifying' the array. – Damien Roche Sep 11 '11 at 14:26
  • Regarding your edit: This seems more like you defined an array and used string keys instead of numerical keys. I assume `new Array('A','B','C')` is not your real code. – Felix Kling Sep 11 '11 at 14:27
  • @Zenph: Show us a testcase on jsfiddle.net that exhibits the issue. Your question is still very vague and lacking any concrete detail. – Lightness Races in Orbit Sep 11 '11 at 14:28
  • Given up. Voting to close. The question can be re-opened if/when it's transformed into something useful and interesting. – Lightness Races in Orbit Sep 11 '11 at 14:31
  • What? Are you ready to try to answer the question? It's quite simple what I'm asking - see the clarification. I haven't seen you contribute positively in any way to any question or answer on this page.. – Damien Roche Sep 11 '11 at 14:33
  • 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
  • @Zenph: And pointing out dangerous lies in answers _is_ constructive. – Lightness Races in Orbit Sep 11 '11 at 14:35
  • 1
    The question is *still* unclear. Your edit is not really helping. What is the problem with specifying the index dynamically? Please create a small example that demonstrates your problem: [SSCCE](http://sscce.org/). – Felix Kling Sep 11 '11 at 14:35

1 Answers1

0

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"]}
Guffa
  • 687,336
  • 108
  • 737
  • 1,005