-2

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

RKCY
  • 4,095
  • 14
  • 61
  • 97
  • 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. – DIEGO CARRASCAL May 27 '16 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. – RKCY May 27 '16 at 14:40

1 Answers1

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"];

gdros
  • 393
  • 2
  • 10