Take the 2-minute tour ×
var generated_Obj= {
              id: 'unqiue',
              some other properties

            var hash = {};

I would be grateful to know how to add generated_Obj to hash using generated_Obj.id as a key.

If a solution with push() method is possible I would like to learn about it either, ofcourse if there's approach that is efficent it's better

10x for your kind help :)

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You can add things to an object (what you called a hash) using the [] operator:

hash[generatedObject.id] = generatedObject;
share|improve this answer
how would you add an object with the same name? –  Trip Dec 10 '12 at 18:59
@Trip: I don't really understand your question. Do you want to have two elements with the same key? –  Tikhon Jelvis Dec 10 '12 at 20:17
I resolved it by using an array. Thanks Tikhon Jelvis! –  Trip Dec 11 '12 at 23:17
add comment

Your Answer


