Add JavaScript object to JavaScript object

后端 未结 5 1272
离开以前
离开以前 2020-12-23 19:36

I\'d like to have JavaScript objects within another JavaScript object as such:

Issues:

  - {\"ID\" : \"1\", \"Name\" : \"Missing Documentation\", \"Notes\"          


        
5条回答
  •  攒了一身酷
    2020-12-23 20:34

    var jsonIssues = [
     {ID:'1',Name:'Some name',Notes:'NOTES'},
     {ID:'2',Name:'Some name 2',Notes:'NOTES 2'}
    ];
    

    If you want to add to the array then you can do this

    jsonIssues[jsonIssues.length] = {ID:'3',Name:'Some name 3',Notes:'NOTES 3'};
    

    Or you can use the push technique that the other guy posted, which is also good.

提交回复
热议问题