Add JavaScript object to JavaScript object

后端 未结 5 1281
离开以前
离开以前 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:19

    As my first object is a native javascript object (used like a list of objects), push didn't work in my escenario, but I resolved it by adding new key as following:

    MyObjList['newKey'] = obj;
    

    In addition to this, may be usefull to know how to delete same object inserted before:

    delete MyObjList['newKey'][id];
    

    Hope it helps someone as it helped me;

提交回复
热议问题