0

Hi everybody I'm a prototype js developer and I'm moving for work/client reasons to jquery. I'm a big fan of Prototype Hash var h = new Hash(); class I know that in jQuery is not any hash table available at least in the core, I would like to know what it the best alternative to have a good practice/solution in a way to manage my data structure in a pretty same way as I do it with the hash table? of course using Jquery.

3
  • What kind of things are you storing in the hashtable? Commented Jan 4, 2012 at 4:08
  • normally I'm storing objects in the way { name : "myname", photos : ["1.jpg","2,jpg"], and : "so on"} basically what I do is ask for specify id in my hash table and retrieve the specific object of that id. for example if I have a list of user in a webpage and an user with id = 3 is clicked. I asked for h.get(3) => { name : "", bla bla}. Commented Jan 4, 2012 at 4:24
  • 2
    You can use an object for that, too: jsfiddle.net/minitech/NJpSB Commented Jan 4, 2012 at 4:28

1 Answer 1

1

If you're only using strings as keys, you can use a plain old object (since you're no longer using Prototype, you don't have to worry much about overwriting things):

var h = {};
h.somekey = somevalue;
h.someotherkey = someothervalue;
h[dynamickey] = val;
Sign up to request clarification or add additional context in comments.

2 Comments

I think I could do something like var h = {}; $.each(jsonResponeList,function(index, item){ h.item.id = item; //I dont know if this is posible hahaha }
@nahum: Certainly it's possible: h.item = { id: item };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.