B
bubbabubbs
Platform: Win2K/SP4
I am trying to use an associative array in JScript, but I am seeing
something weird. Example:
ArrayTest();
///////////////////////////////////////////////////
function ArrayTest()
{
var oArray = new Array( 0 );
dumpArrayKeys( oArray );
++oArray.length;
oArray["first"] = 0;
dumpArrayKeys( oArray );
++oArray.length;
oArray["second"] = 1;
dumpArrayKeys( oArray );
}
///////////////////////////////////////////////////
function dumpArrayKeys( oArray )
{
oLog.Log( "arrayLen: " + oArray.length );
for( var key in oArray )
{
oLog.Log( "key: " + key );
}
Log( "-----------------------------" );
}
///////////////////////////////////////////////////
The output I'm seeing:
arrayLen: 0
key: getKey
-----------------------------
arrayLen: 1
key: getKey
key: first
-----------------------------
arrayLen: 2
key: getKey
key: first
key: second
-----------------------------
I don't understand where the key value "getKey" is coming from or
what it represents. Notice that the key is there as soon as the Array
has been created, and it never goes away.
Thoughts?
I am trying to use an associative array in JScript, but I am seeing
something weird. Example:
ArrayTest();
///////////////////////////////////////////////////
function ArrayTest()
{
var oArray = new Array( 0 );
dumpArrayKeys( oArray );
++oArray.length;
oArray["first"] = 0;
dumpArrayKeys( oArray );
++oArray.length;
oArray["second"] = 1;
dumpArrayKeys( oArray );
}
///////////////////////////////////////////////////
function dumpArrayKeys( oArray )
{
oLog.Log( "arrayLen: " + oArray.length );
for( var key in oArray )
{
oLog.Log( "key: " + key );
}
Log( "-----------------------------" );
}
///////////////////////////////////////////////////
The output I'm seeing:
arrayLen: 0
key: getKey
-----------------------------
arrayLen: 1
key: getKey
key: first
-----------------------------
arrayLen: 2
key: getKey
key: first
key: second
-----------------------------
I don't understand where the key value "getKey" is coming from or
what it represents. Notice that the key is there as soon as the Array
has been created, and it never goes away.
Thoughts?