Appending to an object

后端 未结 13 1457
心在旅途
心在旅途 2020-11-27 10:19

I have an object that holds alerts and some information about them:

var alerts = { 
    1: { app: \'helloworld\', message: \'message\' },
    2: { app: \'hel         


        
13条回答
  •  清酒与你
    2020-11-27 11:17

    You can use spread syntax as follows..

    var alerts = { 
    1: { app: 'helloworld', message: 'message' },
    2: { app: 'helloagain', message: 'another message' }
     }
    
    alerts = {...alerts, 3: {app: 'hey there', message: 'another message'} }
    

提交回复
热议问题