Jump to content

Array problem


dotkpay

Recommended Posts

Hi,

 

I have been sweating with these arrays and I can't seem to see the fault,

The function 'document.write() can only output the first value of the array 'car' and it claims the other values of 'car' are undefined whereas it doesn't output anything for any value of array 'date';

Could someone please look through this code for me.

 

<html>
<head>
<title>Arrays</title>
</head>
<body>
<script type="text/javascript">
var car=new Array();
var home=new Array();
car[0]=1;
date[0]="20/12/2011";
car[1]=10;
date[1]="20/12/2011";
car[2]=11;
date[2]="20/12/2011";
car[3]=12;
date[3]="20/12/2011";
car[4]=2;
date[4]="20/12/2011";
</script>

<script type="text/javascript">
document.write(car[0],"<br>",car[4]);
document.write(date[4]);
</script>
</body>
</html>

Link to comment
Share on other sites

i believe this is because immedietaly following your declaration of car[0] you have the line

 

date[0]="20/12/2011";

 

which will trip an error and render any code after this line useless, due to the fact that you haven't declared the variable date before attempting to use it, as gristoi said. perhaps you meant to declare date instead of home.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.