English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

var loop1
loop1=0
while(loop1<13)
{
coarray[loop1]=new Array()
loop1++
}

coarray[0][0]="Black"
coarray[1][0]="Brown"
coarray[2][0]="Red"
coarray[3][0]="Orange"
coarray[4][0]="Yellow"
coarray[5][0]="Green"
coarray[6][0]="Blue"
coarray[7][0]="Violet"
coarray[8][0]="Grey"
coarray[9][0]="White"
coarray[10][0]="Gold"
coarray[11][0]="Silver"
coarray[12][0]="None"

ive already declared each coarray with an array inside of it, but how do i access it? without doing this

var tempvar=coarray[0]
tempvar[0]="Black"

i didn't want to do that because it would be a hassle :(

2007-09-20 18:57:56 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

ALERT~~~~~~~~~~~~
I FORGOT TO SAY coarray[0][0] doesn't work same as the other coarray
ALERT~~~~~~~~~~~~

2007-09-20 18:58:55 · update #1

NVM since nobody answered this im gona do it the hard way :( this way

var tempvar
tempvar=coarray[0]
tempvar[0]="Black"
tempvar=coarray[1]
tempvar[0]="Brown"
tempvar=coarray[2]
tempvar[0]="Red"
tempvar=coarray[3]
tempvar[0]="Orange"
tempvar=coarray[4]
tempvar[0]="Yellow"
tempvar=coarray[5]
tempvar[0]="Green"
tempvar=coarray[6]
tempvar[0]="Blue"
tempvar=coarray[7]
tempvar[0]="Violet"
tempvar=coarray[8]
tempvar[0]="Grey"
tempvar=coarray[9]
tempvar[0]="White"
tempvar=coarray[10]
tempvar[0]="Gold"
tempvar=coarray[11]
tempvar[0]="Silver"
tempvar=coarray[12]
tempvar[0]="None"

2007-09-20 19:11:32 · update #2

3 answers

So, you want an array of arrays, eh? Why are you using the old-style technique of "coarray[loop1] = new Array()" instead of using the newer literal array "coarray = []" syntax? You could even combine the the literal array syntax with literal object syntax to make your program easier to read:

var coarray = [
    {color: "Black"},
    {color: "Brown"},
    {color: "Red"},
    {color: "Orange"},
    {color: "Yellow"},
    {color: "Green"},
    {color: "Blue"},
    {color: "Violet"},
    {color: "Grey"},
    {color: "White"},
    {color: "Gold"},
    {color: "Silver"},
    {color: "None"}
];

Then you could access the array like this:

var myColor = coarray[0].color;

... or even:

var myColor = coarray[0]["color"];

Of course, if you're really attached to your array of arrays approach, you can do this:

var coarray = [
    ["Black"],
    ["Brown"],
    ["Red"],
    ["Orange"],
    ["Yellow"],
    ["Green"],
    ["Blue"],
    ["Violet"],
    ["Grey"],
    ["White"],
    ["Gold"],
    ["Silver"],
    ["None"]
];

... and still access it like this:

var myColor = coarray[0][0];

It's your choice. Good luck.

2007-09-21 05:37:15 · answer #1 · answered by §©®Î¶†Δ® 4 · 0 0

Well you have come up with a solution and an answer. But what are you trying to do?
You have a two dimension array that only has element [n][0] set to a value. Why what is the point?

If you do not understand how to access an array then why are you using an array?

Oh, I see you don't want hassle! That is not the only reason for using an array.

2007-09-20 19:45:11 · answer #2 · answered by AnalProgrammer 7 · 0 0







2007-09-21 07:32:53 · answer #3 · answered by richarduie 6 · 0 0

fedest.com, questions and answers