javascript append object code example
Example 1: append object to object javascript
const originalObj = { name: 'John', age: 34 }
let newObj = { ...originalObj, city: 'New York' }
newObj = { ...newObj, language: 'en' }
Example 2: object javascript append
var list = [];
list.push({name:'John', last_name:'Doe'});
list.push({name:'Jane', last_name:'Doe'});
console.log(list);
Example 3: javascript append to object
How about storing the alerts as records in an array instead of properties of a single object ?
var alerts = [
{num : 1, app:'helloworld',message:'message'},
{num : 2, app:'helloagain',message:'another message'}
]
And then to add one, just use push:
alerts.push({num : 3, app:'helloagain_again',message:'yet another message'});
Example 4: javascript append to object
var alerts = [
{num : 1, app:'helloworld',message:'message'},
{num : 2, app:'helloagain',message:'another message'}
]
Example 5: javascript append to object
alerts.push({num : 3, app:'helloagain_again',message:'yet another message'});