Answers for "append object to object javascript"

5

append object to object javascript

// Spread syntax allows an iterable (in this case an object) to be expanded

const originalObj = { name: 'John', age: 34 }
let newObj = { ...originalObj, city: 'New York' }
// newObj is now { name: 'John', age: 34, city: 'New York' }

// it can also be used with the same object
newObj = { ...newObj, language: 'en' }
// { name: 'John', age: 34, city: 'New York', language: 'en' }
Posted by: Guest on January-19-2021
1

object javascript append

var list = [];

list.push({name:'John', last_name:'Doe'});
list.push({name:'Jane', last_name:'Doe'});

console.log(list);
/* Result:
[
  {
    "name": "John",
    "last_name": "Doe"
  },
  {
    "name": "Jane",
    "last_name": "Doe"
  }
]
*/
Posted by: Guest on May-04-2020
1

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'});
Posted by: Guest on April-15-2020
0

javascript append to object

var alerts = [ 
    {num : 1, app:'helloworld',message:'message'},
    {num : 2, app:'helloagain',message:'another message'} 
]
Posted by: Guest on December-09-2020
0

javascript append to object

alerts.push({num : 3, app:'helloagain_again',message:'yet another message'});
Posted by: Guest on December-09-2020

Code answers related to "append object to object javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language