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]="Southampto n 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="JavaS cript" type="text/javascript"
src="football.j s"></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. 11 5590
Randell D. wrote: I gather I am initializing the array incorrectly - would someone care to direct me in the right direction?
You should initialize arrays before using them, including multidimensiona l
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
On Sat, 19 Feb 2005 09:30:05 GMT Randell D. wrote: 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]="Southampto n 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="JavaS cript" type="text/javascript" src="football.j s"></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" .
Since you identified it, the script expects something to be in it.
Nothing says you have to use it.
> 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]="Southampto n 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="JavaS cript" type="text/javascript" src="football.j s"></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 : 19 February 2005", [
"Arsenal v Sheff Utd, 12:30",
"Bolton v Fulham, 15:00",
"Charlton v Leicester, 15:00",
"Everton v Man Utd, 17:30",
"Southampto n v Brentford, 15:00"]]];
In this form, it is easier to read, it is easier to modify, and it is
correct. Learn to use the literal notation for arrays and objects.
Also, array subscripts should begin at 0, not 1. http://www.JSON.org
Richard wrote: On Sat, 19 Feb 2005 09:30:05 GMT Randell D. wrote: I have a multi-dimensional array in javascript, as follows: gameRecord=new Array(500); gameRecord[1][1]="FA Cup : 19 February 2005";
<snip> Error: gameRecord[1] has no properties
I gather I am initializing the array incorrectly - would someone care to direct me in the right direction?
<snip> gameRecord[1]="Top_Level" . Since you identified it, the script expects something to be in it. Nothing says you have to use it.
Why do you do this? Even if you cannot see it for yourself you have been
told often enough that you don't know anything about scripting web
browsers. Posting your mystical incantations in response to serious
questions about programming is going to do nobody any good, and make you
look like more of a fool than is already apparent from your established
record on Usenet.
Richard.
On Sat, 19 Feb 2005 08:13:59 -0800 Douglas Crockford wrote: 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]="Southampto n 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="JavaS cript" type="text/javascript" src="football.j s"></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 : 19 February 2005", [ "Arsenal v Sheff Utd, 12:30", "Bolton v Fulham, 15:00", "Charlton v Leicester, 15:00", "Everton v Man Utd, 17:30", "Southampto n v Brentford, 15:00"]]];
In this form, it is easier to read, it is easier to modify, and it is correct. Learn to use the literal notation for arrays and objects.
Also, array subscripts should begin at 0, not 1.
http://www.JSON.org
Subscript arrays always begin at zero.
It is your choice to use it or not to use it.
Besides, he was merely showing an example.
Richard wrote:
[snip]
Douglas was responding to the OP. You were not. Trim unnecessary
quoted material when posting. You read enough technical newsgroups to
know what is expected of you. Subscript arrays [...]
What's a "subscript array"?
It is your choice to use it or not to use it.
It is up the author to decide what to use, yes. However, it may not
have been the intention here to create a sparse array. Indeed, what if
the author uses the length property without realising that it will
reflect the "surplus" element.
Unless the OP is omitting some crucial data, I see no benefit here in
skipping element zero.
Besides, he was merely showing an example.
If the actual code used element zero, why wouldn't this example? In
any case, if the example or the OP doesn't provide enough information
to receive accurate replies, that's the fault of the OP.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Douglas Crockford wrote: 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]="Southampto n 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="JavaS cript" type="text/javascript" src="football.j s"></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 : 19 February 2005", [ "Arsenal v Sheff Utd, 12:30", "Bolton v Fulham, 15:00", "Charlton v Leicester, 15:00", "Everton v Man Utd, 17:30", "Southampto n v Brentford, 15:00"]]];
In this form, it is easier to read, it is easier to modify, and it is correct. Learn to use the literal notation for arrays and objects.
Also, array subscripts should begin at 0, not 1.
http://www.JSON.org
Thanks for the note above, however the above was only a short extract of
a few hundred records and doing it that way could prove cumbersome,
especially in balancing the square brackets.
I've solved the problem though and put it down to not declarying the
multidimension array properly... The Javascript Console in Mozilla no
longer barks back at me...
Thanks for letting me know that arrays should begin with 0 and not 1.
Cheers
Randell D.
Michael Winter wrote: Richard wrote:
[snip]
Douglas was responding to the OP. You were not. Trim unnecessary quoted material when posting. You read enough technical newsgroups to know what is expected of you.
Subscript arrays [...]
What's a "subscript array"?
It is your choice to use it or not to use it.
It is up the author to decide what to use, yes. However, it may not have been the intention here to create a sparse array. Indeed, what if the author uses the length property without realising that it will reflect the "surplus" element.
Unless the OP is omitting some crucial data, I see no benefit here in skipping element zero.
Besides, he was merely showing an example.
If the actual code used element zero, why wouldn't this example? In any case, if the example or the OP doesn't provide enough information to receive accurate replies, that's the fault of the OP.
Mike
What have I started?
I'm glad to hear about the 'zero element' because my array did
(incorrectly) begin with 1, and not zero. In addition, you've helped
correct me in such that I originally believed that js having three
elements numbered (for example) 3, 5 and 9 would give a length of three,
and not nine. I've since references a Core Guide to Javascript that I
downloaded sometime ago from Netscape which supports your arguement, and
throws my previous understanding out the window.
Thanks again for everyone's help.
Randell D.
Randell D. wrote:
[snip] What have I started?
Nothing. It's just RtS being his normal self. Ignore him. :)
I'm glad to hear about the 'zero element' because my array did (incorrectly) begin with 1, and not zero.
Well, as RtS said, you can define entries at any index you like.
However, you must remember that the elements you skip still exist (to
an extent). The length property is updated to reflect the highest
index plus one. So assigning values to elements 3, 5, 9 will result in
a length of ten (*not* nine, as you thought). The other seven elements
will remain undefined.
[snip]
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alexis Nikichine |
last post by:
Hello,
It is common knowledge that arrays can be used as hashtables:
var color = ;
color = 0xFF0000;
color = 0x0000FF;
|
by: VK |
last post by:
Or why I just did myArray = "Computers" but myArray.length is
showing 0. What a hey?
There is a new trend to treat arrays and hashes as they were some
variations of the same thing. But they are not at all.
If you are doing *array", then you have to use only integer values for
array index, as it was since ALGOL.
|
by: VK |
last post by:
A while ago I proposed to update info in the group FAQ section, but I
dropped the discussion using the approach "No matter what color the cat
is as long as it still hounts the mice". Over the last month I had
enough of extra proof that the cat doesn't hount mice anymore in more
and more situations. And the surrent sicretisme among array and hash is
the base for it.
I summarized all points in this article:...
|
by: Robert Mark Bram |
last post by:
Hi All!
How do you get the length of an associative array?
var my_cars= new Array()
my_cars="Mustang";
my_cars="Station Wagon";
my_cars="SUV";
alert(my_cars.length);
|
by: Jon Maz |
last post by:
Hi All,
I'm reasonably proficient with C#, and am starting with php5. I was happy
to learn of the __get and __set methods, but am encountering a problem using
them to set an object property of type "array".
Below is a simple example of the problem I'm having with a sample object
"Article", which has an array property "authors". As you can see, I can't
even use standard php array syntax to set a single author, even though the
same...
| |
by: emma middlebrook |
last post by:
Hi
Straight to the point - I don't understand why System.Array derives
from IList (given the methods/properties actually on IList).
When designing an interface you specify a contract. Deriving from an
interface and only implementing some of it means something is wrong:
either the interface specification is wrong e.g. not minimal or the
derivation is wrong e.g. the type can't actually honour this contract.
|
by: VK |
last post by:
(see the post by ASM in the original thread; can be seen at
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b>
as an option)
As that is not in relevance to "new Array() vs " question or to the
array performance, I dared to move it to a new thread.
Gecko takes undefined value strictly as per Book 4, Chapter 3, Song 9
of Books of ECMA
:-)
|
by: IamIan |
last post by:
I'm using an array to store map features (name, lat, lon, caption,
etc), from which the user can then select an individual feature. The
problem is that when thousands of features are stored in the array,
looping over the entire array looking for a match is SLOW.
So I'm running a hash in parallel, where every time a feature is
pushed onto the array it's name is also added to the hash as an
identical key value pair. I then check if the key...
|
by: julie.siebel |
last post by:
I've been wrestling with a really complex page. All the data is drawn
down via SQL, the page is built via VBScript, and then controlled
through javascript.
It's a page for a travel company that shows all the properties, weeks
available, pricing, etc. for a particular area of Europe. The data
varies widely depending on the region; at times there will be 50
properties, and at other times only a half dozen.
The cross referencing of...
|
by: Pukeko |
last post by:
Hi, this is an array that is used for a dropdown menu.
var imageArray = new Array(
"ecwp://" + document.location.host + "/massey/images/massey/
massey_07_fullres.ecw",
"ecwp://" + document.location.host + "/sampleiws/images/usa/
1metercalif.ecw",
"ecwp://" + document.location.host + "/sampleiws/images/australia/
parramatta.ecw";
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |