« MYB without Glitches | Main | xmlResponse Issues with Facebook »

Hashtable in JavaScript

Hi,

for our MYB project we like to use a hashtable to "centrally" store all information that we get from the web services. A hashtable is in our opinion quite suitable, because you can use keys to store data in a structured manner and to retrieve data quiet easily. Now the issue is that JavaScript offers no real hashtable implementation. The JavaScript Array() can be used with keys, but it is not a real hashtable. Now I found some hashtable implementations on the web, which were coded by private persons. Some of them look quiet code and seem to do the things we need (e.g. this one).
Now I wanted to ask, if anyone of you already has some experience in taking code classes or libraries from the web, that were implemented by "hobby" coders?

André

TrackBack

Listed below are links to weblogs that reference Hashtable in JavaScript:

» Respose: Hashtable in Javascript from Chidambaram's Blog
In response to Andre's blog ... I agree with your choice of Hashtable to store results from your web service call. But, do you really need to implement this at the javascript level ? You should be using a php... [Read More]

Comments (2)

Javascript's native Object data type is meant for exactly the situation you describe. You can use Objects just like Arrays, but they hold only the keys you give them (read here for why to use Object instead of Array: http://www.andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/ )

var data = new Object();
data["key"] = "data value";

Tell me how this is not a hashtable? Why don't you trust the creators of JavaScript to make these operations as fast as possible? They probably base that implementation on a hash table model anyway, so why reinvent the wheel? Use it.

This "Chidambaram" guy is right as well, depending on where you need the data and when, you can decide to store it server-side in a PHP associative array, or client-side in javascript. It all depends on what you need to do with it.

But if you use JavaScript, I assure you, the language is robust and very high-level; don't concern yourself with re-implementing data types it already gives you.

Personally, I'd say to go with this Tristan guy's suggestion. I do have to say that his reference to Chidambaram is quite humorous.

Coding Mix

Web 2.0 Mix

Archives