-1

I have an object where i am associating nested objects. In few places I want to associate array instead of object. Any help how to achive that.

Ex :

{ "Id": "ID1",{
        "Data1" : {
            "myData1" : "myVal1"
        },
        "Data2":[{
            "Dat1" : "val1"
        },{
            "Dat2" : "Val2"
        }]
    }
}

So in this case somewhere I am attacahing associate by using this code

    `ID1[Data1] = "Data1" : {myData1" : "myVal1"}`

Can any body please suggest me how to add array.

David
  • 4,266
  • 8
  • 34
  • 69

1 Answers1

0

You can achieve it as follows:

const obj = {};

obj['prop'] = {
  test: 'test'
};


obj['arr'] = [];

obj['arr'].push({
  test: 'test'
});

console.log(obj);
prasanth
  • 22,145
  • 4
  • 29
  • 53
Shihab
  • 2,641
  • 3
  • 21
  • 29