Appending to an object

后端 未结 13 1314
心在旅途
心在旅途 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'} }
    
    0 讨论(0)
提交回复
热议问题