How can I add javascript object to another object in dynamic

hh54188 picture hh54188 · Apr 12, 2012 · Viewed 54.2k times · Source

Suppose I have several javascript object

{"type":"gotopage","target":"undefined"}
{"type":"press","target":"a"}
{"type":"rotate","target":"long"}

How can I add this objects to another object like

config={}

I know how to if each inserted object have a id I can added as:

config["id"]={}

But in this case how can I add objects without id?

Answer

Boyo picture Boyo · Apr 12, 2012
var obj1 = {"type":"gotopage","target":"undefined"};

var config = {};
config.obj1 = obj1;

You can always add them later.

var obj1 = {"type":"gotopage","target":"undefined"};

var config = {};
config.obj1 = obj1;

var obj2 = {"key":"data"};
config.obj2 = obj2;