WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Associative Arrays, Jose Luis Martinez, June 22, 2004
     Re:Associative Arrays, Erik Arvidsson, July 19, 2004
     Re:Associative Arrays, Jude, July 11, 2004
         Re:Associative Arrays, Erik Arvidsson, July 19, 2004

Subject: Associative Arrays From: Jose Luis Martinez Date: June 22, 2004

Hello,

I was wondering which is the best way of making associative arrays / hashes / dictionaries. I've seen that in standard JS you can do something like this:

var tel = new Array();
tel["jose"] = "333555666"
tel["andy"] = "555666777"
alert ("My tel is: " + tel["jose"]);

This works in Moz/IE.

Looking thru the windows script tecnologies documentation, the array object doesn't mention this feature. Looking a little more I find that in the Script Runtime, MS has put in an ActiveX Dictionary object:
------------------- Cut & Paste ---------------
A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

The following code illustrates how to create a Dictionary object:

[JScript] var y = new ActiveXObject("Scripting.Dictionary"); y.add ("a", "test");
------------ End Cut & Paste -----------

I've used this object for various tasks, and it's been wonderfull... the only thing that bugged me was the "keys()" method. It returns a VBArray... and you have to cast it to a JS Array like this! (new VBArray(d.Keys())).toArray();

Now I find that I'm going crossbrowser, and that I might need the hash functionality... So i don't want to use ActiveX. (I suppose Mozilla can not access this object).

What are the tradeoffs of using method 1 (plain arrays) versus method 2? Does anyone know the implementation differences? What's going on internally? I guess the guys in MS are not stupid, and that they have put in the Dictionary for some reason.

Thank you in anticipation.

Jose Luis Martinez




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX