-1

I have a JSON object with few properties How Do I add properties dynamically to the object?

person({
   'name':Ajay,
    'age':21 });

If i want to add properties like gender or contact to this existing object , how to do it?

2

1 Answer 1

0

I suppose you have function named as person and you are sending a object in that function So to put it simple.

            var obj={"name":"Ajay",
                     "age":"21"
              };
             person(obj);

If you want to add more properties to your obj. You can do it like this:

       obj.sex="Male";
       obj.height="6";
       person(obj);
Sign up to request clarification or add additional context in comments.

4 Comments

how did you know that the scripting language is JavaScript?
In a a json Obj you add prop. like this only . So i just guessed it .
Better to consult/clarify the author before assuming anything, otherwise there is an ocean to assume anything.
In any case the format of JSON will not change right :)

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.