Javascript - array missing values

F

Fred

Group,

I coded this sample htm to show that javascript can drop index values
without any error messages. Does anyone know why this would happen?

Thanks

Fred

sample htm to follow -->

<html>
<BODY>
<br>
<SCRIPT LANGUAGE="Javascript">
document.write ("Sample to show index as 2 digit number");
Monthname = new Array()
Monthname[01] = 'January';
Monthname[02] = 'February';
Monthname[03] = 'March';
Monthname[04] = 'April';
Monthname[05] = 'May';
Monthname[06] = 'June';
Monthname[07] = 'July';
Monthname[08] = 'August';
Monthname[09] = 'September';
Monthname[10] = 'October';
Monthname[11] = 'November';
Monthname[12] = 'December';
document.write ('<br>before for loop lgth=' + Monthname.length)
for (var r=1; r < Monthname.length; r++) {
document.write("<br>" + r + ") " + Monthname[r])
}
document.write ("<br><br>Sample to show index as 4 digit number - missing
Aug and Sept values");
Monthname4 = new Array()
Monthname4[0001] = 'January';
Monthname4[0002] = 'February';
Monthname4[0003] = 'March';
Monthname4[0004] = 'April';
Monthname4[0005] = 'May';
Monthname4[0006] = 'June';
Monthname4[0007] = 'July';
Monthname4[0008] = 'August';
Monthname4[0009] = 'September';
Monthname4[0010] = 'October';
Monthname4[0011] = 'November';
Monthname4[0012] = 'December';
document.write ('<br>before for loop lgth=' + Monthname4.length)
for (var r=1; r < Monthname4.length; r++) {
document.write("<br>" + r + ") " + Monthname4[r])
}
</SCRIPT>
</BODY>
</HTML>
 
M

MD Websunlimited

Hi Fred,

Actually it is doing what it should do under the implementation for "JavaScript" It is interpreting the values as octal digits,
i.e., literals that begin with 00 are considered octal digits.

To confirm this change the following values:
Monthname4[0010] = 'August';
Monthname4[0011] = 'September';
Monthname4[0012] = 'October';
Monthname4[0013] = 'November';
Monthname4[0014] = 'December';



--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp
 
F

Fred

Thanks

Fred

MD Websunlimited said:
Hi Fred,

Actually it is doing what it should do under the implementation for
"JavaScript" It is interpreting the values as octal digits,
i.e., literals that begin with 00 are considered octal digits.

To confirm this change the following values:
Monthname4[0010] = 'August';
Monthname4[0011] = 'September';
Monthname4[0012] = 'October';
Monthname4[0013] = 'November';
Monthname4[0014] = 'December';



--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp


Group,

I coded this sample htm to show that javascript can drop index values
without any error messages. Does anyone know why this would happen?

Thanks

Fred

sample htm to follow -->

<html>
<BODY>
<br>
<SCRIPT LANGUAGE="Javascript">
document.write ("Sample to show index as 2 digit number");
Monthname = new Array()
Monthname[01] = 'January';
Monthname[02] = 'February';
Monthname[03] = 'March';
Monthname[04] = 'April';
Monthname[05] = 'May';
Monthname[06] = 'June';
Monthname[07] = 'July';
Monthname[08] = 'August';
Monthname[09] = 'September';
Monthname[10] = 'October';
Monthname[11] = 'November';
Monthname[12] = 'December';
document.write ('<br>before for loop lgth=' + Monthname.length)
for (var r=1; r < Monthname.length; r++) {
document.write("<br>" + r + ") " + Monthname[r])
}
document.write ("<br><br>Sample to show index as 4 digit number - missing
Aug and Sept values");
Monthname4 = new Array()
Monthname4[0001] = 'January';
Monthname4[0002] = 'February';
Monthname4[0003] = 'March';
Monthname4[0004] = 'April';
Monthname4[0005] = 'May';
Monthname4[0006] = 'June';
Monthname4[0007] = 'July';
Monthname4[0010] = 'August';
Monthname4[0011] = 'September';
Monthname4[0012] = 'October';
Monthname4[0013] = 'November';
Monthname4[0014] = 'December';
document.write ('<br>before for loop lgth=' + Monthname4.length)
for (var r=1; r < Monthname4.length; r++) {
document.write("<br>" + r + ") " + Monthname4[r])
}
</SCRIPT>
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top