“JavaScript Agregar a objetar” Código de respuesta

Agregar objeto a objeto 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' }
YawningPeccary

JavaScript Agregar a objetar

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'});
Ankur

Respuestas similares a “JavaScript Agregar a objetar”

Preguntas similares a “JavaScript Agregar a objetar”

Más respuestas relacionadas con “JavaScript Agregar a objetar” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código