1
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 :)

1 Answer 1

4

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

hash[generatedObject.id] = generatedObject;
Sign up to request clarification or add additional context in comments.

2 Comments

how would you add an object with the same name?
@Trip: I don't really understand your question. Do you want to have two elements with the same key?

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.