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

问题描述



人们


我在javascript中有一个多维数组,如下所示:


gameRecord = new Array(500);

gameRecord [1] [1] =" FA Cup:2005年2月19日" ;;

gameRecord [1] [2] [1 ] =" Arsenal v Sheff Utd,12:30" ;;

gameRecord [1] [2] [2] =" Bolton v Fulham,15:00"

gameRecord [1] [2] [3] =" Charlton v Leicester,15:00;

gameRecord [1] [2] [4] =" Everton v Man Utd, 17:30;

gameRecord [1] [2] [5] =" Southampton v Brentford,15:00";


有很多更多的记录,但上面只是一个提取...

它被写入自己的javascript文件(称为football.js)我用

调用


< script language =" JavaScript" type =" text / javascript"

src =" football.js">< / script>


我知道它正在阅读它,因为一个测试,我在文件前面加了一个

简单警报(here);然后我大喊大​​叫。


为什么即使在我从数组中读取之前,我在Mozilla的JavaScript控制台中收到了

以下错误消息...


错误:gameRecord [1]没有属性


我收集我正在初始化数组错误 - 有人会关心

指引我朝正确的方向发展?


谢谢

Randell D.


Folks

I have a multi-dimensional array in javascript, as follows:

gameRecord=new Array(500);
gameRecord[1][1]="FA Cup : 19 February 2005";
gameRecord[1][2][1]="Arsenal v Sheff Utd, 12:30";
gameRecord[1][2][2]="Bolton v Fulham, 15:00";
gameRecord[1][2][3]="Charlton v Leicester, 15:00";
gameRecord[1][2][4]="Everton v Man Utd, 17:30";
gameRecord[1][2][5]="Southampton v Brentford, 15:00";

There are alot more records to it, but the above is just an extract...
It is written into its own javascript file (called football.js) which I
call using

<script language="JavaScript" type="text/javascript"
src="football.js"></script>

I know its reading it because for a test, I preceeded the file with a
simple alert("here"); and this shouted back at me.

How come though that even before I read from the array I get the
following error message in the JavaScript Console in Mozilla...

Error: gameRecord[1] has no properties

I gather I am initializing the array incorrectly - would someone care to
direct me in the right direction?

Thanks
Randell D.

推荐答案




你应该在使用它们之前初始化数组,包括多维

数组:


var gameRecord = [];

gameRecord [1] = [];

gameRecord [1] [1] =" FA Cup:2005年2月19日" ;;

gameRecord [1] [2] = [];

gameRecord [1] [2] [1] =" Arsenal v Sheff Utd,12:30" ;;

JW



You should initialize arrays before using them, including multidimensional
arrays:

var gameRecord = [];
gameRecord[1] = [];
gameRecord[1][1] = "FA Cup : 19 February 2005";
gameRecord[1][2] = [];
gameRecord[1][2][1] = "Arsenal v Sheff Utd, 12:30";
JW




gameRecord [1] =" Top_Level"。

既然你发现了它,脚本需要其中的东西。

没有什么说你必须使用它。


gameRecord[1]="Top_Level".
Since you identified it, the script expects something to be in it.
Nothing says you have to use it.





gameRecord = [

[" FA Cup:2005年2月19日",[

" Arsenal v Sheff Utd,12: 30",

" Bolton v Fulham,15:00"

" Charlton v Leicester,15:00"

" ; Everton v Man Utd,17:30,

" Southampton v Brentford,15:00"]]];


在这种形式下,它更容易阅读,更容易修改,并且它是正确的。学习对数组和对象使用文字符号。


此外,数组下标应该从0开始,而不是1.



这篇关于数组问题:没有属性 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 10:03