0

I have to create a object key based on some dynamic value . Here the value of str will from user to user. The user enters the value of str. I want to use str value entered by user to create Object.

var str = $('#inputValue');

var obj = new Object();
obj.assignment = new Object();
obj.assignment.name= "assignmentName";
obj.assignment.str = new Object();
2
  • 1
    Duplicate of ~ 1000 questions. Commented Dec 11, 2013 at 12:31
  • I am confused - what the first str is for? Commented Dec 11, 2013 at 12:31

2 Answers 2

4

Use the brackets syntax:

obj.assignment[str] = new Object();

Side note: you can use the shortcut {} to create new objects. For example:

obj.assignment[str] = {};
Sign up to request clarification or add additional context in comments.

Comments

1

New Object:

obj.assignment[str] = {};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.