数组问题:没有属性 - 为什么? [英] Array problem: has no properties - why?

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

问题描述



人们


我在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.

推荐答案

Randell D.写道:
Randell D. wrote:
我收集我正在错误地初始化数组 - 有人会关心
指引我朝正确的方向发展吗?
I gather I am initializing the array incorrectly - would someone care
to direct me in the right direction?




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

数组:


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


2005年2月19日星期六09:30:05 GMT Randell D.写道:

On Sat, 19 Feb 2005 09:30:05 GMT Randell D. wrote:

人们
我在javascript中有一个多维数组,如下所示:
gameRecord = new Array(500);
gameRecord [ 1] [1] ="足总杯: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),我用$ b调用它$ b< 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.



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.


>我在javascript中有一个多维数组,如下所示:
> I have a multi-dimensional array in javascript, as follows:

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语言= QUOT; JavaScript的" type =" text / javascript"
src =" football.js">< / script>

我知道它正在阅读它,因为对于测试,我在文件之前一个简单的警报(这里);然后我大喊大​​叫。

为什么即使在我从数组中读取之前,我在Mozilla的JavaScript控制台中收到了以下错误消息......
<错误:gameRecord [1]没有属性

我收集我正在错误地初始化数组 - 有人会关心
指引我朝正确的方向发展吗?

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?




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.

http://www.JSON.org


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

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