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
https://forums.phpfreaks.com/topic/253554-array-problem/
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
https://forums.phpfreaks.com/topic/253554-array-problem/#findComment-1299787
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.