怎么定义数组的数组? [英] how define array of array?

查看:148
本文介绍了怎么定义数组的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


这可能是我遇到问题的答案 - 或者可能不是

可能吗?!


我可以将变量情况和计数的初始值定义为


var situation = 0;

var count = 0;


在应用程序期间的情况从0到7不等,数从0

到8,


并且有


值[情况] [计数]?


如果是,如何在阵列中定义数组?


谢谢


Geoff

解决方案

在Javascript Arrays中是flat,所以为了制作多个尺寸,你需要创建一个数组作为另一个数组的项目,因此: -


//一个阵列可以是另一个元素的元素ARRAY

var value = new Array();

value [0] = new Array();

value [0] [0] =" value00";

value [0] [1] =" value01";

value [1] = new Array ();

value [1] [0] =" value10";

value [1] [1] =" value11";

alert(value [0] [1]);

// SHORTHAND JSON NOTATION

var value = []; // SAME AS var value = new Array


//等价于上面

var value = [[" value00"," value01"] ,[" value10"," value11"]];

alert(value [0] [1]);


< blockquote>" Geoff Cox" < GE ******* @ notquitecorrectfreeuk.com>在消息中写道

news:ti ******************************** @ 4ax.com ...

你好,

这可能是我遇到的问题的答案 - 或者可能不是可能的?!


var count = 0;

何时在应用程序情况下将从0到7不等,数从0
到8,

值[情况] [数量]?

如果是,如何定义阵列数组?

谢谢



var value = new Array(8);

for(var n = 0; n< value.length; n ++){

value [n] = new Array(9);

}


-

Dag。


2005年9月14日星期三08:34:40 GMT ,Dag Sunde < me@dagsunde.com>写道:

var value = new Array(8);
for(var n = 0; n< value.length; n ++){
value [n] = new Array(9);
}




Dag,


谢谢你上面 - 它帮助我让应用程序正常运行,但是我已经不是很清楚怎么回事了?!


我使用的实际代码是


for(var n = 0; n< slider_value.length; n ++){

slider_value [n] = new Array(8);

}


你会看到我使用的是Array(8)而不是Array(9)。


我正在使用的数组收集一些滑块值,是


slider_value [situation_number] [count]


其中situation_number在0到6之间变化





计数在0到7之间变化。


上面的数组或数组的定义是否适合这个?


干杯


Geoff


Hello,

This may be the answer to a problem I have - or it may not be
possible?!

Can I have initial values of variable situation and count defined as

var situation = 0;
var count = 0;

when during the app situation will vary from 0 to 7 and count from 0
to 8,

and have

value[situation][count] ?

If yes, how do I define the array if arrays?

Thanks

Geoff

解决方案

In Javascript Arrays are "flat", so to make multiple dimensions, you
create an Array as an item of another Array, thus:-

// AN ARRAY CAN BE AN ELEMENT OF ANOTHER ARRAY
var value=new Array();
value[0]=new Array();
value[0][0]="value00";
value[0][1]="value01";
value[1]=new Array();
value[1][0]="value10";
value[1][1]="value11";
alert (value[0][1]);
// SHORTHAND JSON NOTATION
var value=[]; // SAME AS var value=new Array

// EQUIVALENT TO THE ABOVE
var value=[ ["value00","value01"] , ["value10","value11"] ];
alert (value[0][1]);


"Geoff Cox" <ge*******@notquitecorrectfreeuk.com> wrote in message
news:ti********************************@4ax.com...

Hello,

This may be the answer to a problem I have - or it may not be
possible?!

Can I have initial values of variable situation and count defined as

var situation = 0;
var count = 0;

when during the app situation will vary from 0 to 7 and count from 0
to 8,

and have

value[situation][count] ?

If yes, how do I define the array if arrays?

Thanks



var value = new Array(8);
for (var n = 0; n < value.length; n++ ) {
value[n] = new Array(9);
}

--
Dag.


On Wed, 14 Sep 2005 08:34:40 GMT, "Dag Sunde" <me@dagsunde.com> wrote:

var value = new Array(8);
for (var n = 0; n < value.length; n++ ) {
value[n] = new Array(9);
}



Dag,

Thanks for above - it has helped me to get the app working but I am
not quite clear how yet?!

The actual code I use is

for (var n = 0; n < slider_value.length; n++ ) {
slider_value[n] = new Array(8);
}

You will see I use Array(8) rather than Array(9).

The array I am using to collect some slider values, is

slider_value[situation_number][count]

where situation_number varies between 0 and 6

and

count varies between 0 and 7.

Does the defination of the array or arrays above fit in with this?

Cheers

Geoff


这篇关于怎么定义数组的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆