Array object with string indexes causes length property to always return 0 
Author Message
 Array object with string indexes causes length property to always return 0

Hello,

I have created an Array object and I want to assign entries to this Array
using string indexing instead of ordinal indexing.

Example:

var aArray = new Array();
aArray.lastname = "Doe";        // Could also use aArray["lastname"] =
"Doe";  I prefer dot notation
aArray.firstname = "John";
aArray.middle = "P";

This seems to work fine.  However, when you then access the length property
of the Array object it always returns zero.  Why is this so?  Also, I am
unable to use the join method on the Array object to retrieve a list of
delimited values.  Is this possibly caused by using string indexing?

Any help, comments or suggestions would be appreciated.

Rob



Mon, 25 Nov 2002 03:00:00 GMT  
 Array object with string indexes causes length property to always return 0


Fri, 19 Jun 1992 00:00:00 GMT  
 Array object with string indexes causes length property to always return 0
Hello,

Here is an example of the three (3) ways of adding and accessing elements in
an Array object.  It is
obvious that string indexing causing the internal length counting to fail,
which in turn most likely
causes the join method to fail.

Is this a bug?  It happens identically in NS4.x+ and IE4.x+ .

document.write("<br><br>Ordinal Indexing<br>");
var aFinal = new Array();
aFinal[0] = "datatype";
aFinal[1] = "imageobj";
aFinal[2] = "required";
aFinal[3] = "minlength";
aFinal[4] = "maxlength";
aFinal[5] = "minselection";
aFinal[6] = "maxselection";
aFinal[7] = "childrules";
document.write("aFinal.length : " + aFinal.length + "<br>");
document.write("aFinal.join :" + aFinal.join(',') + "<br>");
for (var i=0; i<aFinal.length; i++)
{
 document.write(i + "  : " + aFinal[i] + "<br>");

Quote:
}

document.write("<br><br>String Indexing<br>");
var aFinal = new Array();
aFinal["datatype"] = "datatype";
aFinal["imageobj"] = "imageobj";
aFinal["required"] = "required";
aFinal["minlength"] = "minlength";
aFinal["maxlength"] = "maxlength";
aFinal["minselection"] = "minselection";
aFinal["maxselection"] = "maxselection";
aFinal["childrules"] = "childrules";
document.write("aFinal.length : " + aFinal.length + "<br>");
document.write("aFinal.join :" + aFinal.join(',') + "<br>");
for (var i=0; i<aFinal.length; i++)
{
 document.write(i + "  : " + aFinal[i] + "<br>");

Quote:
}

document.write("<br><br>String Indexing via Dot Notation<br>");
var aFinal = new Array();
aFinal.datatype = "datatype";
aFinal.imageobj = "imageobj";
aFinal.required = "required";
aFinal.minlength = "minlength";
aFinal.maxlength = "maxlength";
aFinal.minselection = "minselection";
aFinal.maxselection = "maxselection";
aFinal.childrules = "childrules";
document.write("aFinal.length : " + aFinal.length + "<br>");
document.write("aFinal.join :" + aFinal.join(',') + "<br>");
for (var i=0; i<aFinal.length; i++)
{
 document.write(i + "  : " + aFinal[i] + "<br>");

Quote:
}



Quote:
> Hello,

> I have created an Array object and I want to assign entries to this Array
> using string indexing instead of ordinal indexing.

> Example:

> var aArray = new Array();
> aArray.lastname = "Doe";        // Could also use aArray["lastname"] =
> "Doe";  I prefer dot notation
> aArray.firstname = "John";
> aArray.middle = "P";

> This seems to work fine.  However, when you then access the length
property
> of the Array object it always returns zero.  Why is this so?  Also, I am
> unable to use the join method on the Array object to retrieve a list of
> delimited values.  Is this possibly caused by using string indexing?

> Any help, comments or suggestions would be appreciated.

> Rob



Mon, 25 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CDO: Parent property always returns session object

2. string object and the length property

3. Index property in control array

4. Array (or any indexed collection) properties in Classes.

5. Arrays, string indices ... and more

6. Retrieving index property, or whatever, of object with multiple entities

7. C++ ActiveX Property returns VARIANT Array of BSTR for VBScript or JavaScript

8. Returning Array of Strings from COM to JScript

9. returning empty variant array from COM object?

10. JavaScript access variant array returned by COM object?

11. Returning array from COM object

12. Returning Arrays from COM object

 

 
Powered by phpBB® Forum Software