-2

I would like to know how to add/ remove properties to object at run time in javascript? How to achieve this in javascript ?

2
  • Could you please give an example of your object and the properties you want to add or remove, also it could be helpful if you explain what you are trying to achieve. Commented May 27, 2016 at 14:37
  • @DIEGOCARRASCAL :- I have an json object with 4 elements and i want to add another element like index or any other element before using the Json object. how can i achieve this. and same for deleting element also. Commented May 27, 2016 at 14:40

1 Answer 1

3

Let's say your object is myobj

then you can add a member like this

myobj.myvar = value; or myobj["myvar"] = value;

and remove it with

delete myobj.myvar; or delete myobj["myvar"];

Sign up to request clarification or add additional context in comments.

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.